Be the first user to complete this post

  • 0
Add to List

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
})



Also Read:

  1. Writing multiline sql queries in javascript using knex
  2. Remove the elements of one array from another using underscore or raw javascript