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

314
Vistas
Why is mocha test throwing "Error done() called multiple times in hook <"before each" ....>?

I am learning about smart contracts and blockchain development. I am currently trying to test the deployment of a simple contract using mocha but when running the test the following error is thrown :

Error: done() called multiple times in hook <"before each" hook for "deploys contract"> (of root suite) at createMultipleDoneError (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/errors.js:428:13) at multiple (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:290:24) at done (/Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:301:14) at /Users/nacholopez/Desktop/Inbox/node_modules/mocha/lib/runnable.js:371:11 at processTicksAndRejections (node:internal/process/task_queues:96:5) { code: 'ERR_MOCHA_MULTIPLE_DONE', valueType: 'undefined', value: undefined

Here is my compilation and testing code:

compile.js:

const path = require('path');
const fs = require('fs');
const solc = require('solc');
const Inboxpath = path.resolve(__dirname, 'contracts', 'Inbox.sol');
const source = fs.readFileSync(Inboxpath, 'utf8');

const input = {
    language: "Solidity",
    sources: {
        "Inbox.sol": {
            content: source,
        },
    },
    settings: {
        outputSelection: {
            "*": {
                "*": ["*"],
            },
        },
    },
};
const output = JSON.parse(solc.compile(JSON.stringify(input)));

module.exports = output.contracts["Inbox.sol"].Inbox;

Inbox.test.js :

const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());
const { abi, evm } = require('../compile');

let accounts;
let inbox;

beforeEach(async () => {
    accounts = await web3.eth.getAccounts();
    inbox = await new web3.eth.Contract(abi).
        deploy({ data: evm.bytecode.object, arguments: ['hi there'] }).
        send({ from: accounts[0], gas: '1000000' });
});

describe('Inbox', () => {
    it('deploys contract', () => {
        console.log(inbox);
    });
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I ran into the same issue as well and I made the callback to the 'it' function 'async' and that fixed the issue for me.

it("deploys a contract", async () => {
        assert.ok(inbox.options.address);
    });
about 4 years ago · Juan Pablo Isaza Denunciar
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