Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can you mock functions from a module? #223

Open
sunnz opened this issue Jan 14, 2022 · 0 comments
Open

can you mock functions from a module? #223

sunnz opened this issue Jan 14, 2022 · 0 comments

Comments

@sunnz
Copy link

sunnz commented Jan 14, 2022

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

@sunnz sunnz changed the title can you mock modules and functions? can you mock funcitons from a module? Jan 31, 2022
@sunnz sunnz changed the title can you mock funcitons from a module? can you mock functions from a module? Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant