#5251·mocha

Bug: Tests pass without running after uncaught exception

Author: JoshuaKGoldbergCreated Nov 13, 2024Updated Sep 17, 2026
Labelstype: bugstatus: accepting prs

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have '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, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

If an uncaught exception occurs, I would think Mocha should report a failure and continue running subsequent tests.

Actual

If a test throws an error inside a process.nextTick callback, Mocha correctly reports that test failing, but then doesn't run subsequent tests. It reports them as passed.

For example, in the MRE, there are three tests -a, b, and c- and b throws an error inside process.nextTick. The report is:

  a
    ✔ should pass

  b
    ✔ should pass, then fail
    1) should pass, then fail


  2 passing (3ms)
  1 failing

  1) b
       should pass, then fail:
     Uncaught Error: uncaught!!
      at /Users/josh/repos/repros/test/example-b.js:4:15
      at process.processTicksAndRejections (node:internal/process/task_queues:77:11)

Minimal, Reproducible Example

https://github.com/JoshuaKGoldberg/repros/tree/mocha-skip-test-after-uncaught

bash
git clone https://github.com/JoshuaKGoldberg/repros -b mocha-skip-test-after-uncaught
npm i
npx mocha

Versions

  • Mocha: 10.8.2
  • Node: 18, 20, and 22

Additional Info

Discovered in #5250 -> 6b5ff680716f2a67d7783bdb0874054841bdd5ce.

Somewhat similar-looking to #5184 but not the same.