I encountered an error with my jasmine test, where I was expecting the spy openQuickSubtypes
to have been called.
The issue arose while I was working on implementing a context menu.
component.html
<div class="each-shift" *ngFor="let shift of shiftsWithEmptyBoxes">
<div class="shift-cover" [ngClass]="shiftDetails(shift)">
<div class="requested-vertical-bar"
[ngClass]="getShiftVerticalBarColor(shift)"></div>
<div class="shift-left-box" #subtype (contextmenu)="openQuickSubtypes(subtype, subtypeMenu, shift); $event.preventDefault();">
{{ showShiftOverTime(shift) }}
{{ getShiftSubTypeLetter(shift, false) }}
{{ showSubTypeShiftNotation(shift) }}
</div>
component.ts
openQuickSubtypes(origin:any,menu:any,index:number)
{
this.contextService.openContextMenu(origin,menu,this.viewContainerRef,{data:index})
.subscribe(openMenu=>{
})
}
my test case: test case should open right click
it('should right click', fakeAsync(() => {
component.shiftsWithEmptyBoxes = [{
"shiftId": 130374,
"shiftType": "empty"
}
];
fixture.detectChanges();
const menuClick = fixture.debugElement.query(By.css('.shift-left-box'));
const spyonOpenQuickSubtypes = spyOn(component, 'openQuickSubtypes').and.callThrough();
const event = new MouseEvent('click',
{
view: window,
bubbles: true,
cancelable: true,
relatedTarget: document
});
menuClick.nativeElement.dispatchEvent(event);
fixture.detectChanges();
fixture.whenStable().then(() => {
expect(spyonOpenQuickSubtypes).toHaveBeenCalled();
});
}));
Every time I run the test case, I keep encountering the same error:
Error: Expected spy openQuickSubtypes to have been called.