Show Buttons
Share On Facebook
Share On Twitter
Share On Google Plus
Share On Linkdin
Share On Reddit
Share On Stumbleupon
Contact us
Hide Buttons

How to set the timeout of a test in mocha

Mocha uses a default timeout of 2000 ms. However, if for some reason that does not work for your use case, you can increase the timeout for a particular test. You can do so by using this.timeout(timeout);

Adding a timeout to the describe applies it to all the nested describe/it blocks unless overriddden.

NOTE: If you are using ES6 fat arrow functions as your describe function, you cannot access the this and hence cannot use this.timeout. You will need to change your describe blocks to use regular es5 functions instead.

e.g

describe(() => { // Using fat arrows as the describe function
    this.timeout(5000); // This will not work
})

describe(function () { // Using es5 function definition
    this.timeout(5000); // This works
})

Ryan Sukale

Ryan is just a regular guy next door trying to manage his life and finances.

You may also like...