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 time­out of 2000 ms. How­ever, if for some rea­son that does not work for your use case, you can increase the time­out for a par­tic­u­lar test. You can do so by using this.timeout(timeout);

Adding a time­out to the describe applies it to all the nested describe/it blocks unless overriddden.

NOTE: If you are using ES6 fat arrow func­tions as your describe func­tion, you can­not access the this and hence can­not use this.timeout. You will need to change your describe blocks to use reg­u­lar es5 func­tions instead.


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...