I am working on a project where I have a file called mainFile
that utilizes a method named helperMethod
. This method, which resides in a separate file called helperFile
, returns a Promise. How can I mock the output of the helperMethod
?
Here is the structure of my files -
helperFile:
export function helperMethod() {return a Promise}
module.exports.helperMethod = helperMethod;
mainFile:
import helperMethod from helperFile;
methodInMainFile() {console.log(helperMethod);}
Test file for mainFile:
import methodInMainFile from mainFile;
import * as utils from helperFile;
sinon
.stub(utils, 'helperMethod')
.returns(Promise.resolve(madeUpResponse));
methodInMainFile();
The current code snippet displays Promise { undefined }
. Is there a way to make it display Promise { madeUpResponse }
? It seems like the helperMethod
isn't being invoked based on the console log message I added.