Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

310
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!