Mocha
DeveloperOpenJS Foundation
Initial releaseNovember 22, 2011 (2011-11-22)
Stable release
11.7.7[1] Edit this on Wikidata / 14 June 2026; 1 day ago (14 June 2026)
Written inJavaScript
PlatformNode.js
TypeTest automation framework
LicenseMIT
Websitemochajs.org
Repositorygithub.com/mochajs/mocha

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

References

edit
  1. ^ "Release 11.7.7". 14 June 2026. Retrieved 15 June 2026.
  2. ^ "Mocha - the fun, simple, flexible JavaScript test framework". mochajs.org.
edit

📚 Artikel Terkait di Wikipedia

Jasmine (software)

Karma, a simple JavaScript test runner tool. Mocha is another popular Javascript testing framework. The comparison between Jasmine and Mocha is given in the

JavaScript

JavaScript (JS) is a programming language and core technology of the Web, alongside HTML and CSS. Created by Brendan Eich in 1995, it is maintained by

Mocha

singer, and politician Mocha (decompiler), for the Java language Mocha (JavaScript framework), for writing unit tests Mocha, the working title of the

Comparison of JavaScript-based web frameworks

web frameworks for front-end web development that are reliant on JavaScript code for their behavior. JavaScript-based web application frameworks, such

List of unit testing frameworks

qunitjs.com. "Unit testing framework for Javascript". unitjs.com. "RhUnit - A QUnit compatible Javascript unit testing framework for Rhi…".{{cite web}}:

List of JavaScript engines

first JavaScript engines were interpreters of the source code, but modern engines use just-in-time compilation to improve performance. JavaScript engines

List of JavaScript libraries

list of notable JavaScript libraries. Cassowary (software) CHR.js Google Polymer Dojo Toolkit jQuery MooTools Prototype JavaScript Framework AnyChart Apache

List of TypeScript software and tools

runtimes, web frameworks, compilers, integrated development environments, libraries, and other development utilities. Babel — JavaScript compiler with