mercredi 2 mai 2018

Jasmine-Tests - Get elements inside

I would like to test HTML elements within a ng-tamplate.

<ng-template>
  <button class="create"></button>
</ng-template>

Jasmine Test:

fixture = TestBed.createComponent(SomeComponent);
const htmlElement: HTMLElement = fixture.nativeElement;
// Does not work:
const p = htmlElement.querySelector('.create');

How can I get the html element inside the ng-template? If I place the button outside of the ng-template tag, it works. I think it has something to do with the shadow dom.

Versions: Jasmine 2.8.0; Angular 5.2.9

Aucun commentaire:

Enregistrer un commentaire