the fun, simple, flexible JavaScript test framework

Mocha is a feature-rich JavaScript check framework working on Node.js and within the browser, making asynchronous testing easy and enjoyable. Mocha checks run serially, permitting for versatile and correct reporting, whereas mapping uncaught exceptions to the right check circumstances. Hosted on GitHub.

Use Mocha at Work? Ask your supervisor or advertising group in the event that they’d assist assist our mission. Your organization’s brand will even be displayed on npmjs.com and our GitHub repository.

# Backers

Discover Mocha useful? Develop into a backer and assist Mocha with a month-to-month donation.

# Options

# Desk of Contents

# Set up

Set up with npm globally:

$ npm set up --global mocha

or as a growth dependency in your mission:

$ npm set up --save-dev mocha

As of v8.0.0, Mocha requires Node.js v10.12.Zero or newer.

# Getting Began

$ npm set up mocha
$ mkdir check
$ $EDITOR check/check.js 

In your editor:

var assert = require('assert');
describe('Array', perform() {
  describe('#indexOf()', perform() {
    it('ought to return -1 when the worth just isn't current', perform() {
      assert.equal([1, 2, 3].indexOf(4), -1);
    });
  });
});

Again within the terminal:

$ ./node_modules/mocha/bin/mocha

  Array
    
      ✓ ought to return -1 when the worth just isn't current


  1 passing (9ms)

Arrange a check script in package deal.json:

"scripts": {
  "check": "mocha"
}

Then run checks with:

$ npm check

# Run Cycle Overview

Up to date for v9.0.0.

The next is a mid-level define of Mocha’s “circulation of execution” when run in Node.js; the “much less necessary” particulars have been omitted.

In a browser, check information are loaded by