I have a module which contains two functions where function A calls function B. I only want to mock function B because it's doing some hard to test logic, but keep function A unmocked.
Functions:
export functionB = () => {
}
export functionA = () => {
return functionB()
}
I know I can update the original file like this but this seems messy to me.
functionB = () => {
}
functionA = () => {
return exportFunctions.functionB()
}
const exportFunctions = {
functionA,
functionB
};
export default exportFunctions;
I'm doing:
jest.mock("functions", () => ({
...(jest.requireActual("functions") as object),
functionB: jest.fn()
}))
But when I test functionA, it's still calling the actual functionB implementation which makes sense. But I don't know how to inject a new definition of functionB into the call without rewriting the function in a mock. Is this possible?
Thanks in advance!