In this sample test file I saw two different syntax
one is const app = fixture.debugElement.componentInstance; and another is const compiled = fixture.nativeElement; I don't know what is different between these two syntax?
I am totally new with angular testing and I am applying it to my project but it is confused to me a little bit about this.
describe('AppComponent (initial CLI version)', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
it('should create the app', async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app).toBeTruthy();
}));
it(`should have as title 'app'`, async(() => {
const fixture = TestBed.createComponent(AppComponent);
const app = fixture.debugElement.componentInstance;
expect(app.title).toEqual('app');
}));
it('should render title in a h1 tag', async(() => {
const fixture = TestBed.createComponent(AppComponent);
fixture.detectChanges();
const compiled = fixture.nativeElement;
expect(compiled.querySelector('h1').textContent).toContain('Welcome to app!');
}));
});
Aucun commentaire:
Enregistrer un commentaire