I want to write some tests using mocha and ganache-cli for my contract. I tried to deploy a compiled contract like so:


const assert = require('assert');
const ganache = require('ganache-cli');
const Web3 = require('web3');
const web3 = new Web3(ganache.provider());

const compiledZombieFactory = require('../ethereum/build/ZombieFactory.json');

let accounts;
let factory;

beforeEach(async () => {
    accounts = await web3.eth.getAccounts();

    factory = await new web3.eth.Contract(compiledZombieFactory.abi)
        .deploy({data: '0x' + compiledZombieFactory.evm.bytecode.object})
        .send({from: accounts[0], gas: '3000000'});


describe('ZombieFactory', () => {
    it('deploys the zombie factory', () => {

When I run this using npm run test, I get the following error:

    1) "before each" hook for "deploys the zombie factory"

  0 passing (2s)
  1 failing

  1) "before each" hook for "deploys the zombie factory":
     Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.

I did some research and I suppose this error occurs because the code fails to deploy the contract successfully. I would like to know if this issue is due to the deploy code or something else.


2 Answers 2


ganache-cli is a bit to deprecated at this point. It is recommended to use truffle develop which replaces ganache-cli and supports latest Solidity versions.

You can find out a lot more from this awesome guy:

// Truffle Toolkit + Truffle Scripts

// Actual Testing

Good Luck !

  • 1
    I realized that working with latest versions of all packages without using a suite like truffle isn't a good idea. I started using truffle and everything works great now. Thanks buddy!
    – roheat
    Commented Apr 3, 2019 at 11:43

Found the solution!

[email protected] is not that stable. Use the most stable release (as of now as version 1.0 is still in beta).

So basically: Uninstall npm uninstall [email protected]

Install npm install --save [email protected]

The same code runs without throwing any errors :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.