I'm having a simple "util" module with a default export and 2 named exports.
const foo = () => 'foo'
export default foo
export const bar = () => 'bar'
export const baz = () => 'baz'
on my test, I'm mocking it like that :
jest.mock('./util', () => ({
__esModule: true,
default: jest.fn(() => 'mocked foo'),
bar: jest.fn(() => 'mocked bar'),
baz: jest.fn(() => 'mocked baz'),
}))
describe('util', () => {
//...
})
On my component, when I call foo(), bar() or baz(), I received undefined.
but everything is working if I remove jest.fn() like that :
jest.mock('./util', () => ({
__esModule: true,
default: () => 'mocked foo',
bar: () => 'mocked bar',
baz: () => 'mocked baz',
}))
My example is very close to the one on jest doc : https://jestjs.io/docs/mock-functions#mocking-partials
I'm using React (CRA) and TypeScript
I know there is different ways to mock a module but I'm curious to understand the issue that I'm facing.
any idea what I'm doing wrong ? :) Thanks !