I have the following module in my codebase:
const getSomething = () => new SomeThirdPartyCall();
const doSomethingElse = () => {
const foo = getSomething();
foo.bar();
};
const someService = { getSomething, doSomethingElse };
export { somethingService };
The way export works is to preserve service name in the calls, i.e. somethingService.doSomethingElse
call will always be consistent across the app.
Now I'm trying to test doSomethingElse
method and mocking getSomething
to avoid calling 3rd party lib but it just doesn't work and still calls that 3rd party. What I tried:
somethingService.doSomethingElse = jest.fn().mockReturnValueOnce(); // doesnt work
const doSomethingElseMock = jest.spyOn(somethingService, 'doSomethingElse');
doSomethingElseMock.mockReturnValueOnce() // doesnt work
doSomethingElseMock.mockImplementationOnce() // doesnt work
What did I miss and why it's not mocking the function?