I'm trying to mock a function of an object with Jest and Typescript and it just does not work. Here is a short version of what I have:
// myModule.ts
export const Foo = {
doSomething: () => {
// ... does something
console.log('original implementation');
}
}
Then in my test:
jest.mock('.myModule.ts', () => {
return {
Foo: {
doSomething: jest.fn().mockImplementation(() => {
console.log('mock implementation')
})
}
}
})
// .. further down in the test
Foo.doSomething();
Shouldn't the console.log('mock implementation') be called when I call Foo.doSomething()? It doesn't error and it's not calling the original implementation anymore, but it's also not calling my mockImplementation.