In my code, I have an if condition inside a function that looks like this:
public setOption() {
setTimeout(() => {
if (this.isCMode && !this.quest['isCompleted']) {
this.toggleOption(false);
}
},window['TIME_OUT']);
As part of testing this function, I attempted to write a jasmine test case for it as shown below:
it('should call toggleOption from setSaqOption if isTimeCompleted is false', () => {
component.isCMode = true;
const tSpy = spyOn<any>(component, 'toggleOption');
component.setOption();
fixture.whenStable().then(() => {
if (component.isCMode && !component.quest['isTimeCompleted']) {
expect(tSpy).toHaveBeenCalled();
}
});
});
However, when running the test case, it fails and gives an error message saying "Expected spy toggleOption to have been called." Can anyone help me identify where I might be going wrong in my test case setup?