I'm writing tests for a React application which makes use of Fluxxor to provide an event dispatcher. Making that work requires telling Jest not to mock a few modules which are used internally, and are provided by Node itself.
That means I can't just add them to the unmockedModulePathPatterns
config key, and instead have to use some code like this:
[ 'util', 'events' ].forEach(function (module) {
jest.setMock(module, require.requireActual(module));
});
However, I can't find anywhere useful to put it. I've got a setupEnvScriptFile
which sets up a few globals that I use in almost all my tests, but the jest
object doesn't seem to be available in that context, so I can't just set the mocks there.
As a hacky stopgap measure I've wrapped the code above in a function which I call at the beginning of any describe
blocks testing Fluxxor stores, but its far from ideal.
unmockedModulePathPatterns
? – DisgustingunmockedModulePathPatterns
has had no effect when I've tried it with the following patterns:util
/usr/lib/node/util
/usr/lib/node
In every case theutil
module gets mocked anyway. – Magicianutil
itself might not be mocked, but that it loads other modules which get mocked? – Disgustingutil
itself that gets mocked, since when I userequire.requireActual
I get the expectedutil
object, and if I don't, then I get a Jest mock. – Magician