Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

271
Visualizações
How to globally enable immer mapSet for all Jest tests?

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.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda