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

149
Visualizações
How to config jest to work with ES6 modules? Javascript

I'm using JEST for testing some javascript code in ES6 Modules. It looks like this:

import Block from "./block.js";

export default class Blockchain {
  constructor() {
    this.chain = [Block.genesis()];
  }

  addBlock({ data }) {
    const previousBlock = this.chain[this.chain.length-1];
    const newBlock = Block.mineBlock({ lastBlock:previousBlock, data });
    this.chain.push(newBlock);
  }
}

But when I executed the unit tests it appears the following message:

ReferenceError: module is not defined in ES module scope This file is being treated as an ES module because it has a '.js' file extension and '/mnt/c/Users/carlo/Documents/github-repos/blockchain_development/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.

I'm using Babel for compiling the ES6 modules and the development script works perfectly. So the problem is related with Jest not being able to execute the ES6 Modules. If anyone can help me out with this I would appreciate it.

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