Skip to content

Commit

Permalink
docs(index): add missing doc link
Browse files Browse the repository at this point in the history
Re: #3135
  • Loading branch information
vkarpov15 committed Jan 15, 2018
1 parent c7730a6 commit c3bfc58
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion docs/index.md
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,40 @@ 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:

```
$ ./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 c3bfc58

Please sign in to comment.