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?
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... });
This “done” parameter, when present in your callback function, tells Mocha that you are writing an asynchronous test.
According to it, tests are run synchronously. This only shows that ordered code is run in order. That doesn't happen by accident.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With