I try to mock PrimeNg MenuItem commend event but its not cover in coverage report.Can anyone please help me to write Jest unit test for 'command' (primeNg Click Event) in primeNg menu. I have already covered sortColumnsUp function with a test case.. but still below line showing as not covered.
How to cover that statement in jest coverage report.............
This is my code
this.itemsWithdraw = [
{
label:'Withdraw Applicant',
icon:'pi pi-fw pi-pencil',
command: e => this.viewApplicantWithdraw(this.selectedGridMenuItem.reqTpsReferenceId),
disabled: this.sharedService.isMspUser(),
},
{
label:'History',
icon:'pi pi-eye',
command: e => this.getRequisitionSubmissionStatusHistoryById(this.selectedGridMenuItem.submissionId),
}
];
I got the answer ...
let viewApplicantWithdrawspy= jest.spyOn(ApplicantSubmissionSearchComponent.prototype as any, 'viewApplicantWithdraw').mockReturnValue(true);
let getRequisitionSubmissionStatusHistoryByIdspy= jest.spyOn(ApplicantSubmissionSearchComponent.prototype as any, 'getRequisitionSubmissionStatusHistoryById').mockReturnValue(true);
this.selectedGridMenuItem={reqTpsReferenceId:1,submissionId:2,appTpsReferenceId: 3, submissionReferenceId: 4,applicantId:5,companyId:6}
let isMspUserSpy = jest.spyOn(sharedServiceMock, 'isMspUser').mockReturnValue(true);
this.itemsWithdrawMock = [
{
label:'Withdraw Applicant',
icon:'pi pi-fw pi-pencil',
command: jest.fn((event?: any) => {}),
disabled: isMspUserSpy
},
{
label:'History',
icon:'pi pi-eye',
command: jest.fn((event?: any) => {})
}
];
this.itemsWithdraw[0].command();
this.itemsWithdraw[1].command();
expect(viewApplicantWithdrawspy).toHaveBeenCalledWith(1);
expect(getRequisitionSubmissionStatusHistoryByIdspy).toHaveBeenCalledWith(2)
expect(isMspUserSpy).toBeCalled();