Let's say I have a method bestFunction in module.js as so:
//module.js
export const bestFunction = x => {
return x + 1
}
How do I mock bestFunction if my code itself is importing as so:
import { bestFunction } from './module.js'
In your test:
import * as depends from './module.js';
describe("when testing..", () => {
beforeEach(() => {
depends.bestFunction = jest.fn().mockImplementation(() => 22);
})
it ('doStuff', () => {
expect(objectUnderTest.foo()).toEqual('22 red balloons');
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With