Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase timeout for a single test case in mocha

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?

like image 822
Mahendra S Avatar asked Apr 12 '13 12:04

Mahendra S


People also ask

How do I increase my Mocha timeout?

Whenever you run Mocha at the command line, it will read this file and set a timeout of 5 seconds by default. Another way which may be better depending on your situation is to set it like this in a top level describe call in your test file: describe("something", function () { this. timeout(5000); // tests... });

What is done () in Mocha?

This “done” parameter, when present in your callback function, tells Mocha that you are writing an asynchronous test.

Do Mocha tests run sequentially?

According to it, tests are run synchronously. This only shows that ordered code is run in order. That doesn't happen by accident.


1 Answers

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); 
like image 63
Dan Kohn Avatar answered Oct 07 '22 23:10

Dan Kohn