Bug: `--timeout 0` does not disable timeouts
Author: bdcarrCreated Feb 24, 2022Updated Sep 17, 2026
Labelstype: bugstatus: accepting prssemver-major
Prerequisites
- Checked that your issue hasn't already been filed by cross-referencing issues with the
faqlabel - Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
- 'Smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, your usage of Mocha, or Mocha itself
- Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with:
node_modules/.bin/mocha --version(Local) andmocha --version(Global). We recommend that you not install Mocha globally.
Description
I ran a mocha test using IntelliJ's debugger, which automatically sets --timeout 0. Left it paused for several minutes while looking at something, and when I resumed it, it timed out.
Steps to Reproduce
- Create a test script containing a single describe() and a single it() (you can do more, this is just a simple example)
- Inside the describe(), put
this.timeout(T)(I haven't tried with the timeout() call inside the it(), not sure if behaviour changes) - Ensure somehow that the
it()will take longer thanTto run: set a breakpoint, or add code that will take longer than that - Run the test with
--timeout 0
Working example
- Check out https://github.com/bdcarr/mocha-timeout-bug/tree/main
cd newversionnpm installnpm run test
There's also an oldversion folder which contains the same test script, but the package.json is set to use [email protected], which is the last version where this issue doesn't occur. I checked with v8.0.0 and the issue occurs.
Expected behavior: No matter how long the test takes, it will not time out if run with --timeout 0
Actual behavior: The test times out after T milliseconds

Reproduces how often: 100%
Versions
- The output of
mocha --versionandnode_modules/.bin/mocha --version: No global install. Issue reproduced on v8.0.0 and v9.2.1. Issue does not occur on v7.2.1. - The output of
node --version: v14.9.0 - Your operating system
- name and version: MacOS 12.2.1
- architecture (32 or 64-bit): 64-bit
- Your shell (e.g., bash, zsh, PowerShell, cmd): zsh v5.8
- Any third-party Mocha-related modules (and their versions): n/a
- Any code transpiler (e.g., TypeScript, CoffeeScript, Babel) being used (and its version): n/a, straight NodeJS with no imports
Source: mochajs/mocha