lundi 23 avril 2018

Test to verify that component element exists in DOM - Jasmine & Angular

Hello Stack Overflow Community,

I’m having issues writing a simple Jasmine Unit Testing in Angular 5 to verify the existence of an element in the DOM for components. As an example, a Movie Component with a selector of app-movie.

I have a successful test for standard HTML elements, such as p: expect(fixture.debugElement.query(By.css('p')).nativeElement).toBeTruthy();

But, this results in a TypeError: Cannot read property 'nativeElement' of null for a particular Components, i.e. app-movie

it ('should have a element selector called app-root in DOM', () => { expect(fixture.debugElement.query(By.css(‘app-movie’)).nativeElement).toBeTruthy();

Can you please advise how to do this? Many thanks!

Aucun commentaire:

Enregistrer un commentaire