I have the following test:
const mockedObject = {
mockedMethod: jest.fn((someKey, someValue) => {
return {someKey: 'someValue'}
})
};
jest.doMock('../myObject', () => {
return mockedObject;
});
testedObject.testedMethod();
expect(mockedObject.mockedMethod).toHaveBeenCalled();
Here, in the testedObject
, I am importing myObject
. I would like to mock that import and pass mockedObject instead
.
After looking at this question and this question, I think the above code should be good, however mockedObject.mockedMethod
is never called even though testedObject
is making the call.
So what is wrong with the mocking done in this test?