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

135
Visualizações
Jest unit test breaking because of import

So I have a file with utils:

import { someFunc, someOtherFunc } from 'someFile.js';

export const util1 = () => { return { abc: 1} };

export const util2 = (a, b) => { return someOtherFunc(a, b) + someFunc(a, b) };

Then I have another file with tests:

import { util1 } from 'utils.js';

describe('Whatever', () => {
  it('Does something', () => {
     const x = { a: 1 };
     const y = util1(x);

     expect(y).toEqual({ abc: 1 });
  });
});

As you can see I'm not importing util2, but when I run jest, it breaks the test suite. This is because of someFunc, but that function is not being used here so I don't know how to ignore it...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Install
npm install --save-dev @babel/plugin-transform-modules-commonjs
  1. Create .babelrc with
{
 "env": {
  "test": { 
   "plugins": ["@babel/plugin-transform-modules-commonjs"]
  }
 }
}
  1. If still does not work, try put "type": "module" in your package.json
about 4 years ago · Juan Pablo Isaza Relatório
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