Reputation: 3678
I am trying to test my component using jasmine
but I am not sure why i fail
here is y code
https://stackblitz.com/edit/angular-bup8gb
describe('initial display',()=>{
it('show counter text',()=>{
debugEl = fixture.debugElement.query(By.css('p.abc'));
el = fixture.nativeElement;
fixture.detectChanges();
expect(el.textContent).toEqual('counter 1')
})
})
Upvotes: 1
Views: 577
Reputation: 25161
Here is the proper syntax to do what you need:
describe('initial display',()=>{
it('show counter text',()=>{
debugEl = fixture.debugElement.query(By.css('.abc'));
el = debugEl.nativeElement; //** You need to get the element from the degubEl
fixture.detectChanges();
expect(el.textContent).toEqual('counter 1')
})
})
Here is another way to do it, but it may not be desirable if you have more than one p
element in the template:
describe('initial display',()=>{
it('show counter text',()=>{
el = fixture.nativeElement;
fixture.detectChanges();
expect(el.querySelector('p').textContent).toEqual('counter 1')
})
})
Upvotes: 1