I have no idea why in my Angular project, Jasmin alwasys return null when I'm trying to access a HTML's element!
it('should find the <p> with fixture.debugElement.query(By.css)', () => {
const bannerDe: DebugElement = fixture.debugElement;
const paragraphDe = bannerDe.query(By.css('p'));
const p: HTMLElement = paragraphDe.nativeElement;
expect(p.textContent).toEqual('banner works!');
});
<p class="title">banner works!</p>
I also have tried to call 'fixture.whenStable().then' but again it returns null!
it('should find the <p> with fixture.debugElement.query(By.css)', () => {
const fixture = TestBed.createComponent(MobileAppLinkComponent);
fixture.detectChanges();
fixture.whenStable().then(() => {
const bannerDe: DebugElement = fixture.debugElement;
const paragraphDe = bannerDe.query(By.css('p'));
const p: HTMLElement = paragraphDe.nativeElement;
expect(p.textContent).toEqual('banner works!');
})