I'm trying to test the intention of the click event inside an *ngFor but I can't make the test pass.
this is my template:
<div class="container-notification-item" *ngFor="let item of menu.detail">
<div class="notification-item" (click)="getDetailsMessage(item)">
<div class="notification-item__icon" [ngClass]="item.iconStyle">
<span>
<i class={{item.icon}}></i>
</span>
</div>
<div class="notification-item__text text-muted">
<h6 [attr.class]="item.textStyle" [ngStyle]="{'font-size':'1.2rem' }">{{item.title}}</h6>
<div>
<p *ngIf="item.detail" class="detail-title">{{item.detail}}</p>
<p *ngIf="item.time" class="detail-time">
<i class="mdi mdi-clock-outline"></i>
<span>{{item.time}}</span>
</p>
</div>
</div>
</div>
</div>
this is my component:
export class AccountMenuComponent implements DropdownMenuComponentInterface {
@Input() menu: DropdownMenu;
redirect = false;
constructor() { }
getDetailsMessage(item?: DropdownMenuDetail) {
this.redirect = true;
}
getDetailsMessages() {
console.log(this.menu.detail);
}
}
and this is my test:
it('must redirect to view all messages', () => {
fixture.detectChanges();
fixture.whenStable().then(() => {
const elem: DebugElement[] = fixture.debugElement.queryAll(By.css('.notification-item'));
console.log(elem[0]);
elem[0].triggerEventHandler('click', null);
expect(component.redirect).toBeTruthy();
})
})
when I do a console.log of the elem variable I have the html element selected but the test fails.