QuickDevGuide

Home › Mocha JS Testing

Timeouts, Retries & Slow Tests — Mocha JS Testing

Mocha fails a test that takes longer than 2000 ms by default and highlights tests slower than 75 ms. Setting Scope How Timeout global --timeout 5000 or timeout: 5000 in .mocharc Timeout suite / test this.timeout(5000) (needs function, not arrow) Disable timeout debugging this.timeout(0) Slow threshold any this.slow(300) / --slow 300 Retries suite / test this.retries(2) / --retries 2 Retries help with genuinely flaky external dependencies (end-to-end tests), but they hide real bugs in unit tests — fix flakiness instead. For timers, use fake timers (Sinon) rather than real waits.

Key Takeaways