I'm trying to test a directive, called AceDirective (I'm using the ace-editor). So first I've build a TestComponent called MockSearchDirective which has got this directive:
@Component({
selector: '[testAce]',
directives: [AceDirective],
template: '<div ace-editor></div>',
}) class TestAce {}
class MockSearchDirective {
}
Now if got my beforeEach and beforeEachProviders with the needed Injections:
beforeEachProviders( () => [
provide(SearchDirective, {useClass: MockSearchDirective}),
TestComponentBuilder,
provide(DataTransportService, {useClass: MockDataTransportService}),
]);
beforeEach( inject( [TestComponentBuilder], (_tcb : TestComponentBuilder) => {
this.searchDirective = new MockSearchDirective();
this._dataTransportService = new MockDataTransportService();
_tcb
.createAsync(TestAce)
.then( (fixture : ComponentFixture<TestAce>)=> {
console.log(fixture);
this.fixture = fixture;
});
}));
This console.log prints the correct fixture containing the Ace-Editor. But, in the specific test:
it('Check if editor will be initiated correctly', (done) => {
console.log(this.fixture);
// let testAce = this.fixture.componentInstance;
// let element = this.fixture.nativeElement;//.querySelector('div')
// let elementRef = this.fixture.elementRef;
//editor exists
expect(this.fixture.elementRef).toBeDefined();
done();
});
It fails. The console.log says, that this.fixture is undefined.
I also tried to inject the TextComponentBuilder in the test (and not via beforeEach):
it('Check if editor will be initiated correctly', inject( [TestComponentBuilder], (_tcb : TestComponentBuilder) => {
_tcb
.createAsync(TestAce)
.then( (fixture : ComponentFixture<TestAce>)=> {
console.log(fixture);
// let testAce = this.fixture.componentInstance;
// let element = this.fixture.nativeElement;//.querySelector('div')
// let elementRef = this.fixture.elementRef;
//editor exists
expect(fixture.elementRef).toBeDefined();
});
}));
but then I've got some timeout:
zone.js:461 Unhandled Promise rejection: 'expect' was used when there was no current spec, this could be because an asynchronous test timed out
Does anyone know this error? And how to deal with it?
Thanks!
Aucun commentaire:
Enregistrer un commentaire