looking to mock a function (foo) imported from a module (../foo), for example when using jest:
jest.mock('../foo'); // this happens automatically with automocking
const foo = require('../foo');
// foo is a mock function
foo.mockImplementation(() => 42);
foo();
// > 42
looking to mock a function (foo) imported from a module (../foo), for example when using jest:
see https://jestjs.io/docs/mock-functions#mock-implementations
I am doing this for an existing codebase that uses ts-mockito, so don't want to throw jest into the mix. :)