Test Timeout Switched Off

ID

javascript.mocha_timeout_zero

Severity

high

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

JavaScript

Tags

reliability, testing

Description

Reports a test timeout switched off rather than raised: this.timeout(0), or the legacy this.enableTimeouts(false). Zero does not mean "no limit is needed", it means "wait forever".

Both the per-declaration form and the chained one are reported: this.timeout(0) inside a test, hook or suite callback, and it('…​', fn).timeout(0).

Deliberately out of scope, because it is not in the source this rule parses: the same setting written as a runner argument, in a run configuration file or a CI command.

Rationale

// Bad
it('imports the catalogue', function () {
  this.timeout(0);
  return importCatalogue();
});
  • A test that hangs — on a promise that never settles, a socket that never answers, a fake clock that is never advanced — takes the whole run with it.

  • CI reports the job as timed out with no indication of which test was waiting, so the diagnosis starts from nothing. The per-test limit exists precisely so that a hang is reported as one failing test.

  • The limit is usually switched off to make an intermittent failure go away, which converts a fast, attributable failure into a slow, anonymous one.

  • A test with no limit also has no stated expectation about how long the operation should take, so a tenfold regression in that operation passes unnoticed.

Remediation

Raise the limit to the time the test needs. A number keeps the failure attributable and documents the expectation.

// Good
it('imports the catalogue', function () {
  this.timeout(60_000);
  return importCatalogue();
});

If the operation genuinely has no predictable duration, the test needs a different shape — poll for the condition with its own bounded wait, so the failure is reported against this test.

© 2026 Xygeni. All rights reserved