I keep trying to stub this function within a module in a format like so (myModule.js):
module.exports = function (config) {
setUpModule(config);
async function myFunction(parameters) {
// logic...
}
return {
myFunction,
};
}
In my tests, I try to stub it like:
`beforeEach(() => {
myFunctionStub = sinon.stub(myModule, 'myFunction').resolves(['apple', 'orange', 'grape']);
});
afterEach(() => {
sinon.restore();
});`
Yet I keep getting: TypeError: Cannot stub non-existent property myFunction
Am I bringing in the function incorrectly? I have tried using the prototype keyword with the same result.
I have seen examples of using stub this way, and then using the instance of the module created to run tests on. I want to globally stub the function so that when other functions create their own instances of the module and run myFunction, that will return the stubbed value. I am quite new to stubbing with sinon, so maybe I am missing something obvious or misunderstanding the scope of what I can stub here.
I would appreciate any advice. Thank you!
Tried prototype keyword, stubbing as myModule()/myModule().prototype, but cannot get the function to be properly globally stubbed