API Reference
Mocha
Feature-rich JavaScript test framework for Node.js and browsers, running tests serially for flexible reporting.
Official Documentation ↗CompatibilityThis documentation covers version
v10. Check the official docs for the latest API surface.Installation
npm
npm install --save-dev mochaMethods
No methods match this filter.
Mocha provides the test structure and runner while leaving assertions to a library such as chai or node:assert.
Key Features
- describe and it structure with hooks
- Serially ordered execution for predictability
- Many reporters and async-first design
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
FAQ
- Does Mocha include assertions?
- No. Mocha only structures and runs tests. Pair it with node:assert, chai, or should for assertions.
- How do I run TypeScript specs?
- Register a loader such as ts-node or tsx with mocha --loader or the require option in .mocharc, then point it at the .ts glob.
- Why do my async tests time out?
- A spec that returns nothing but starts async work finishes immediately. Return the promise or call done so Mocha knows when it is complete.
Report a problem with this API docOpens a pre-filled issue on GitHub.