lundi 7 août 2017

Angular testing click event

At the moment I'm trying to learn more about testing in Angular (v2+), but I'm stuck at testing click events in a *ngFor loop.

This is the HTML-code:

<div *ngIf="selectedHero">...</div>
<ul class="heroes">
  <li *ngFor="let hero of heroes" (click)="onSelect(hero)" [class.selected]="hero === selectedHero">
    <span class="badge"></span> 
  </li>
</ul>

This is the onSelect event:

onSelect(hero:Hero):void{
    this.selectedHero = hero;
}

I have two questions:

  1. How to write a test that checks if the click event works?
  2. How to write a test that makes the div element visible when the variable selectedHero is set?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire