samedi 25 août 2018

When mocking core modules in Jest, don't mock it in dependencies

When I mock a core module in Jest, like jest.mock('fs'), and I create a file called __mocks__/fs.js, then I am using a mocked version of the module.

However, if any of the dependencies in the modules I'm testing also use fs, then they use the mocked version, which breaks them.

Is there a way to unmock these core modules, when they are used by deps, but otherwise not in my own modules?

Or is there an alternative way to achieve this?

Aucun commentaire:

Enregistrer un commentaire