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.