I am writing tests for a React application that uses Fluxxor to provide an event dispatcher. Doing this requires Jest not to make fun of the few modules that are used internally and provided by Node themselves.
This means that I canβt just add them to the unmockedModulePathPatterns configuration key, but should use the following code instead:
[ 'util', 'events' ].forEach(function (module) { jest.setMock(module, require.requireActual(module)); });
However, I cannot find anything useful to use it. I have setupEnvScriptFile that installs several globals that I use in almost all of my tests, but the jest object does not seem to be available in this context, so I cannot just install mocks there.
As a hacker stop measure, I wrapped the code above in the function that I call at the beginning of any describe block for testing Fluxxor stores, but this is far from ideal.
unit-testing reactjs reactjs-flux jestjs
Jon wood
source share