I'm running my tests on a private chain and some of them times out:

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

I tried to set timeout to the whole test or to the before part as per mocha documentation:

contract("looong tests", accounts => {


before( done => {

I got this error:

  1)  "before all" hook:
     TypeError: _this.timeout is not a function

Adding -t command line parameter doesn't seem to have any effect:

truffle test myTest.js -t 40000
truffle test myTest.js --timeout 40000

I see an old pending fix in truffle: https://github.com/trufflesuite/truffle/issues/261

How can I increase the timeout for the before statement?

Adding timeout to individual test cases works but not for before statement :(

   it('one long test', () => {
    }).timeout(40000 ); 

EDIT: I've a workaround for now, moved the code from before to the first test which I've made sync:

   it('should go to before block but can't set timeout there', done =>  {
        new Promise( async function (resolve, reject) {
          // my before code 
        }).then( res => {
    }).timeout(40000 ); 

4 Answers 4


Add this in your Truffle configuration file (truffle.js or truffle-config.js):

mocha: {
    enableTimeouts: false,
    before_timeout: 120000 // Here is 2min but can be whatever timeout is suitable for you.

If you want to preserve timeouts (and even configure different timeouts for different tests), then simply follow the instructions here.

  • I did not succeed in making this work, it always uses the default 120sec timeout. Does it work with latest Truffle version? Sep 10, 2019 at 12:52
  • @NicolasMassart: You down-vote my answer and then expect me to help you??? This answer has been here for more than a year and nobody has complained (and 4 have voted for it)! Has it occurred to you that perhaps your problem is due to some other reason? Sep 10, 2019 at 13:05
  • wow, cool down. I did not downvoted you, I downvoted your answer. The fact is that your answer did not solve my issue and seems to have no effect. So if you can show me I'm wrong I can deal with removing the downvote and let this answer have more visibility. And please forgive me if you were upset by that, I did not think it was so important for you to be upvoted. Sep 10, 2019 at 13:19
  • @NicolasMassart: To begin with, I cannot show you that you're wrong because you're not the original poster of the question, and so i have absolutely no idea what you env looks like, what your tests look like, what your Truffle setup is, what your Truffle version is, and so forth. For example, you could have placed that mocha in the wrong place within your Truffle configuration file. Or you could possibly have two configuration files - truffle.js or truffle-config.js - Truffle would default for the former, but you've added mocha to the latter. Sep 10, 2019 at 13:24
  • And there are of course many other scenarios which I cannot possibly tell without seeing your setup. Second, it does indeed upset me that you post a comment and then immediately down-vote an answer which has apparently been there for quite a while and helped quite a few people, none of which has complained! So yes, I would think twice before taking that road. I would weigh all the possible options, and then start by thinking "what did I do wrong" instead of "what's wrong with an answer which has been used by the community for quite some time"!!! Sep 10, 2019 at 13:26

As an amendment to the answer provided by goodvibration: it matters where you place that code snippet inside of truffle.js. For me it only worked inside of module.exports at the highest level (not inside of other things like networks).

Here is what worked for me:

module.exports = {
  mocha: {
    enableTimeouts: false

The options for Mocha seems to have changes more frequently than expected.

As of the Truffle v5.1.9, the Mocha used is v5.2.0, And the options for Mocha class can be found at the source code located here : https://github.com/mochajs/mocha/blob/v5.2.0/lib/mocha.js#L83

There are options like the followings

  • enableTimeouts - boolean, Enable timeouts?
  • timeout - number|string, Specify test timeout threshold (in milliseconds)
  • bail - boolean, Bail after first test failure?
  • retries - number, Retry failed tests this many times

Later version of the Truffle may use higher version of Mocha. Then, you'd better check the change of options in above GitHub source changing the tags.


you cannot access this from a () => {} style function. If you want to use this.timeout() in the before block you need to do a

before(function() {

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.