Mocha (JavaScript framework)

JavaScript test framework running on Node.js

For other uses, see Mocha.

This article has multiple issues. Please help improve it or discuss these issues on the talk page. (Learn how and when to remove these messages)

This article needs additional citations for verification. Please help improve this article by adding citations to reliable sources. Unsourced material may be challenged and removed.
Find sources: "Mocha" JavaScript framework – news · newspapers · books · scholar · JSTOR (February 2022) (Learn how and when to remove this message)

|

The topic of this article may not meet Wikipedia's notability guidelines for products and services. Please help to demonstrate the notability of the topic by citing reliable secondary sources that are independent of the topic and provide significant coverage of it beyond a mere trivial mention. If notability cannot be shown, the article is likely to be merged, redirected, or deleted.
Find sources: "Mocha" JavaScript framework – news · newspapers · books · scholar · JSTOR (August 2014) (Learn how and when to remove this message)

|

(Learn how and when to remove this message)

Mocha

Developer(s)| OpenJS Foundation
Initial release| November 22, 2011 (2011-11-22)
Stable release|

11.2.0[1] / 17 March 2025; 17 days ago (17 March 2025)

Repository| github.com/mochajs/mocha
Written in| JavaScript
Platform| Node.js
Type| Test automation framework
License| MIT
Website| mochajs.org

Mocha is a JavaScript test framework for Node.js programs, featuring browser support, asynchronous testing, test coverage reports, and use of any assertion library.[2]

## Assertion libraries

[edit]

Mocha can be used with most JavaScript assertion libraries, including:

* should.js
* express.js
* chai
* better-assert
* unexpected

## Usage and examples

[edit]

$ npm install -g mocha
$ mkdir test
$ $EDITOR test/test.js # or open with your favorite editor

var assert = require("assert")
describe('Foo', function(){
describe('#getBar(value)', function() {
it('should return 100 when value is negative') // placeholder
it('should return 0 when value is positive', function() {
assert.equal(0, Foo.getBar(10));

$  mocha

1 test complete (1ms)

For asynchronous testing, invoke the callback, and Mocha will wait for completion.

describe('Foo', function(){
describe('#bar()', function() {
it('should work without error', function(done) {
var foo = new Foo(128);
foo.bar(done);

## See also

[edit]

* Free and open-source software portal

* Jasmine
* List of unit testing frameworks
* npm
* QUnit
* JavaScript framework
* JavaScript library

## References

[edit]

1. ^ "Release 11.2.0". 17 March 2025. Retrieved 27 March 2025.
2. ^ "Mocha - the fun, simple, flexible JavaScript test framework". mochajs.org.

## External links

[edit]

* Official website
* mocha on GitHub

* v
* t
* e

JavaScript

Code analysis|

* ESLint
* JSHint
* JSLint

Supersets|

* JS++
* TypeScript
* ArkTS

Transpilers|

* AtScript
* Babel
* ClojureScript
* CoffeeScript
* Dart
* Elm
* Emscripten
* Google Closure Compiler
* Google Web Toolkit
* Haxe
* LiveScript
* Morfik
* Nim
* Opa
* PureScript
* Reason
* WebSharper

Concepts|

* JavaScript library
* JavaScript syntax

Debuggers|

* Chrome DevTools
* Firefox Inspector
* Komodo IDE
* Microsoft Edge DevTools
* Opera DevTools
* Safari Web Inspector

Doc generators|

* JSDoc

Editors (comparison)|

* Ace
* Cloud9 IDE
* Atom
* CodeMirror
* Brackets
* Light Table
* PhpStorm
* Orion
* Visual Studio
* Visual Studio Express
* Visual Studio Code
* Visual Studio Team Services
* Vim

Engines|

* List of ECMAScript engines

Frameworks|

* Comparison of JavaScript frameworks
* List of JavaScript libraries

Related technologies|

* Ajax
* AssemblyScript
* asm.js
* Cascading Style Sheets
* Document Object Model
* HTML
* HTML5
* JSON
* WebAssembly
* WebAuthn

Package managers|

* npm
* pnpm
* yarn

Module bundlers|

* Webpack
* Vite
* esbuild

Server-side|

* Active Server Pages
* Bun
* CommonJS
* Deno
* JSGI
* Node.js

Unit testing frameworks (list)|

* Jasmine
* Mocha
* QUnit

People|

* Douglas Crockford
* Ryan Dahl
* Brendan Eich
* John Resig

*[v]: View this template
*[t]: Discuss this template
*[e]: Edit this template