Mocha TIMEOUTS

TIMEOUTS

SUITE-LEVEL

Suite-level timeouts may be applied to entire test “suites”, or disabled via this.timeout(0). This will be inherited by all nested suites and test-cases that do not override the value.

describe(‘a suite of tests’, function() {
this.timeout(500);

it(‘should take less than 500ms’, function(done){
setTimeout(done, 300);
});

it(‘should take less than 500ms as well’, function(done){
setTimeout(done, 250);
});
})
TEST-LEVEL

Test-specific timeouts may also be applied, or the use of this.timeout(0) to disable timeouts all together:

it(‘should take less than 500ms’, function(done){
this.timeout(500);
setTimeout(done, 300);
});
HOOK-LEVEL

Hook-level timeouts may also be applied:

describe(‘a suite of tests’, function() {
beforeEach(function(done) {
this.timeout(3000); // A very long environment setup.
setTimeout(done, 2500);
});
});
Again, use this.timeout(0) to disable the timeout for a hook.

In v3.0.0 or newer, a parameter passed to this.timeout() greater than the maximum delay value will cause the timeout to be disabled.

Questions