I'm trying to simulate and meet the else condition for the method below, but I keep receiving an error stating Expected spy modalService.open not to have been called.
Below is the code snippet of the component:
After changing the line component.isError = true;
The If block wasn't highlighted, yet the error persists
public importDeals(upload, list) {
this.fileName = '';
let ngbModalOptions: NgbModalOptions = {
backdrop : 'static',
keyboard : false,
windowClass: 'custom-class'
};
if (!this.isError) {
this.uploadModalRef = this.modalService.open(upload, ngbModalOptions);
}
this.tempContingency = list;
}
Here's the current unit test case (Jasmine)
it('should import deals', () => {
// component.importDeals;
// expect(component.importDeals('upload','list')).toBeUndefined();
component.importDeals;
component.uploadModalRef = jasmine.createSpyObj('uploadModalRef', ['close']);
let mockOptions: NgbModalOptions = {
backdrop : 'static',
keyboard : false,
windowClass: 'custom-class'
};
const mockConfirm = 'confirm-template';
component.importDeals(mockConfirm,'');
expect(modalService.open).toHaveBeenCalledWith(mockConfirm, mockOptions);
});
it('should not import deals', () => {
component.importDeals;
component.modalService = jasmine.createSpyObj('modalService',['open'])
const mockConfirm = 'confirm-template';
component.importDeals(mockConfirm,'');
expect(modalService.open).not.toHaveBeenCalled();
});
Please advise on what could be causing the issue here. Thank you.