PACKAGE · TESTING

mocha

Classic, reliable, trusted test framework for Node.js and the browser

WEEKLY DOWNLOADS 14.5M
STARS 22.9K
FORKS 3.3K
OPEN ISSUES 249
GZIP SIZE 32.0 kB
UNPACKED SIZE 1.4 MB
DEPENDENCIES 16
LAST UPDATED 9mo ago
DOWNLOAD TRENDS

mocha downloads · last 12 months

Download trends for mocha1 download series from Nov 2025 to Oct 2026. Use left and right arrow keys to inspect monthly values.017.7M35.4M53.1M70.8MNov 2025FebMayAugOct 2026
mocha
ABOUT MOCHA

Mocha is a JavaScript test framework for Node.js and browsers. It provides a structure for defining and running tests, helping teams check expected behavior and identify regressions across application code without requiring tests to follow a single assertion style.

Mocha’s design centers on a classic, established testing workflow and support for both BDD and TDD approaches. It is suited to developers who want to organize tests around their own conventions and tools, rather than adopt a framework that dictates every part of the testing stack.

Tests are commonly organized into suites and cases using Mocha’s BDD-style `describe` and `it` APIs, with setup and cleanup handled through hooks such as `before`, `after`, `beforeEach`, and `afterEach`. Mocha runs the tests and reports their outcomes; assertion and mocking choices can be made separately, allowing projects to compose a test stack around those responsibilities.

Mocha fits Node.js and browser testing workflows, and its topics include JavaScript, BDD, TDD, and testing tools. Its suite-and-hook structure can be used to group related checks, prepare shared state, and clean up after cases; browser use also makes it relevant when tests need to run outside a Node-only environment.

The package is at version 12.0.3, uses the MIT license, and reports 4.7 million weekly downloads, 22.9K GitHub stars, and 3.1K forks. Its listed gzip bundle size is 32.0 kB and unpacked size is 1.4 MB; those figures describe different packaging measures and should be considered in the context of whether tests run in Node.js or are bundled for a browser.

Mocha is a test runner, not a complete, all-in-one testing stack: teams should plan how assertions, test doubles, and browser execution fit into their workflow. Its 228 open issues and listed last-updated date of 2026-10-21 are project metadata, not a guarantee about support response times or suitability for a particular environment.

WHEN TO USE
  • When organizing JavaScript tests into named BDD suites and cases, use `describe` and `it` to make the test structure explicit.
  • When test cases need predictable setup and cleanup, use `before`, `after`, `beforeEach`, and `afterEach` hooks around shared resources or per-test state.
  • When applying a TDD workflow, use Mocha as the runner for repeatedly executing focused test cases as implementation changes.
  • When the same project needs test execution in Node.js and browser environments, consider Mocha’s stated support for both runtimes.
  • When you want to choose assertion and mocking tools independently, use Mocha for test organization and execution while composing those other parts of the stack separately.
  • When integrating a JavaScript testing workflow that benefits from a mature, established framework, consider its 12.0.3 release and reported usage and repository figures as context for evaluation.
WHEN NOT TO USE
  • If you want one package to provide the test runner, assertions, and test doubles as a unified stack, Mocha’s runner-focused role means you will need to select and integrate those capabilities separately; choose an all-in-one testing approach instead.
  • If your team wants a test framework that prescribes its own assertion and mocking conventions, Mocha’s composable approach may require more configuration; use a framework with those conventions built in.
  • If tests must run only in a browser and the project requires a browser-focused test workflow beyond Mocha’s stated browser support, assess a browser-specific testing approach before adopting Mocha.
  • If you need a test framework whose API and conventions are fixed by an existing project, check compatibility with Mocha’s `describe`, `it`, and hook patterns first; otherwise, use the project’s established test runner.
  • If deployment constraints make the listed 1.4 MB unpacked package size unsuitable, review the actual installation and browser-bundling path before adopting Mocha; use a smaller testing setup if it better fits those constraints.
  • If current maintenance status is a deciding factor, verify the repository’s present activity rather than relying only on the supplied 228 open issues and 2026-10-21 update date.

CORRECTIONS

Spot wrong data here?

A short note helps us fix it.

Anonymous · No account · No email back

COMPARISONS 11
mocha vs jest ★ 45.5K · 62.1M/wk mocha vs nightwatch ★ 12.0K · 131.8K/wk mocha vs fast-check ★ 5.3K · 75.4M/wk mocha vs @testing-library/react ★ 19.7K · 98.8M/wk mocha vs ava ★ 20.8K · 593.9K/wk mocha vs vitest ★ 17.5K · 189.7M/wk mocha vs selenium-webdriver ★ 34.6K · 2.1M/wk mocha vs jasmine-core ★ 15.8K · 6.3M/wk mocha vs chai ★ 8.3K · 216.8M/wk mocha vs cypress ★ 51.0K · 7.5M/wk mocha vs playwright ★ 101.1K · 178.1M/wk