Skip to content

Commit

Permalink
docs(index): add missing doc link (#3203); closes #3135
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 authored and boneskull committed Jan 17, 2018
1 parent 401997f commit f8a1d2a
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js](https://n
- [mocha.opts file support](#mochaopts)
- clickable suite titles to filter test execution
- [node debugger support](#-d---debug)
- detects multiple calls to `done()`
- [detects multiple calls to `done()`](#detects-multiple-calls-to-done)
- [use any assertion library you want](#assertions)
- [extensible reporting, bundled with 9+ reporters](#reporters)
- [extensible test DSLs or "interfaces"](#interfaces)
Expand Down Expand Up @@ -143,6 +143,39 @@ Then run tests with:
$ npm test
```

## Detects Multiple Calls to `done()`

If you use callback-based async tests, Mocha will throw an error if `done()` is called multiple times. This is handy for catching accidental double callbacks.

```javascript
it('double done', function(done) {
// Calling `done()` twice is an error
setImmediate(done);
setImmediate(done);
});
```

Running the above test will give you the below error message:

```sh
$ ./node_modules/.bin/mocha mocha.test.js


✓ double done
1) double done

1 passing (6ms)
1 failing

1) double done:
Error: done() called multiple times
at Object.<anonymous> (mocha.test.js:1:63)
at require (internal/module.js:11:18)
at Array.forEach (<anonymous>)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
```

## Assertions

Mocha allows you to use any assertion library you wish. In the above example, we're using Node.js' built-in [assert](https://nodejs.org/api/assert.html) module--but generally, if it throws an `Error`, it will work! This means you can use libraries such as:
Expand Down

0 comments on commit f8a1d2a

Please sign in to comment.