NagRock / ts-mockito

Mocking library for TypeScript
MIT License
969 stars 93 forks source link

can you mock functions from a module? #223

Open sunnz opened 2 years ago

sunnz commented 2 years ago

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

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. :)