How to mock a function call inside another function in JavaScript?
Code example:
returnNumber.js
export default function returnNumber() {
return 5;
}
myFunction.js
import returnNumber from "./returnNumber";
export default function myFunction(input) {
return input + returnNumber();
}
I would like to test it by doing something like this, but none if the code examples I saw seem to be working in my case
import myFunction from "./myFunction";
test("myFunction should equal 6", async () => {
returnNumber = () => {
return 1
}
expect(myFunction(5)).toEqual(6);
});
Considering the example above; can I test myFunction while overriding returnNumber’s return value?