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

Prototype JavaScript Framework

The Prototype JavaScript Framework is a JavaScript framework created by Sam Stephenson in February 2005 as part of Ajax support in Ruby on Rails. It is

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

Bootstrap (front-end framework)

open-source CSS framework directed at responsive, mobile-first front-end web development. It contains HTML, CSS and (optionally) JavaScript-based design

Web framework

JavaScript and only refresh parts of the page, are called single-page applications and typically make use of a client-side JavaScript web framework to

Dojo (web framework)

modular JavaScript library or (or more specifically toolkit or UI framework) designed to ease the rapid development of cross-platform, JavaScript/Ajax-based

Ajax (programming)

The Asynchronous JavaScript and XML, usually referred to as Ajax (or AJAX, /ˈeɪdʒæks/) is a set of web development techniques that uses various web technologies

Gatsby (software)

Gatsby, Inc.. Free and open-source software portal React Next.js JavaScript framework "Gatsby Plugins". Gatsby, Inc. Retrieved 2022-02-19. "Using Server-side

Electron (software framework)

using web technologies (mainly HTML, CSS and JavaScript, although other technologies such as front-end frameworks and WebAssembly are possible) that are rendered