How to increase timeout for a single test case in mocha

Mahendra S picture Mahendra S · Apr 12, 2013 · Viewed 157.8k times · Source

I'm submitting a network request in a test case, but this sometimes takes longer than 2 seconds (the default timeout).

How do I increase the timeout for a single test case?

Answer

Dan Kohn picture Dan Kohn · Apr 13, 2013

Here you go: http://mochajs.org/#test-level

it('accesses the network', function(done){
  this.timeout(500);
  [Put network code here, with done() in the callback]
})

For arrow function use as follows:

it('accesses the network', (done) => {
  [Put network code here, with done() in the callback]
}).timeout(500);