timkindberg / jest-when

Jest support for mock argument-matched return values.
MIT License
734 stars 38 forks source link

How to use with mock modules? #18

Closed antoniogiroz closed 5 years ago

antoniogiroz commented 5 years ago

I mock a module like so:

const { aMethodInTheModule } = require('./myModule');

jest.mock('./myModule', () => ({
  aMethodInTheModule: jest.fn(),
}));

Then, the below code doesn't works:

when(aMethodInTheModule)
  .calledWith('a')
  .mockReturnValue(() => Promise.resolve('b'));
timkindberg commented 5 years ago

I guess you figured it out :)