I need to run the following library setup code on Jest initialization:
import { enableMapSet, enableES5 } from "immer";
enableMapSet();
enableES5();
I do this when initializing my CRA app and storybook, but now Jest started crashing too.
I tried using globalSetup like this:
// jest.config.js
module.exports = {
testMatch: ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(test).[jt]s?(x)"],
globalSetup: "./jest.setup.js",
};
// jest.setup.js
import { enableMapSet, enableES5 } from "immer";
// <- also tried calling the setup fns on this very line, with no luck
export default () => {
enableMapSet();
enableES5();
};
but to no avail, I'm still getting the error:
src/xxx/myTest.test.js
● Test suite failed to run
[Immer] The plugin for 'MapSet' has not been loaded into Immer. To enable the plugin, import and call `enableMapSet()` when initializing your application.
8 |
> 9 | export const immerFreeze = <T extends any>(x: T): T => produce(x, _noop);
| ^
produce is default export from "immer", _noop is just lodash noop.
What is the correct way to run my setup code? I'd hate do have to do it in each test individually.