I have simple service that I need unit tested using jest:
the crux of the code is this:
domtoimage.toBlob(node, {filter: filter})
.then(function (blob) {
FileSaver.saveAs(blob, fileName);
});
I have wrote my unit test module as such:
import FileSaver from "file-saver";
import domtoimage from "dom-to-image";
jest.mock('dom-to-image', () => {
return {
toBlob: (arg)=>{
let promise = new Promise((resolve, reject) => {
resolve('myblob')
});
return promise;
}
}
});
jest.mock('file-saver', ()=>{
return {
saveAs: (blob, filename) =>{
return filename;
}
}
});
And in my test, I have the following spy set up
const spy = jest.spyOn(FileSaver, 'saveAs');
and calling my in-test function.
however, the expect statement: expect(spy).toBeCalled()
returns false:
expect(jest.fn()).toBeCalled()
However, in webstorm, when I debug the unit test, I can clearly see that my mocked function is being called (the breakpoint is reached inside function).
What am i missing?