Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

141
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda