Skip to content

Commit

Permalink
docs: Error/undefined params to the 'done' callback
Browse files Browse the repository at this point in the history
  • Loading branch information
maraisr committed Jan 3, 2018
1 parent dc12bd5 commit 0a3569d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ Mocha allows you to use any assertion library you wish. In the above example, w

## Asynchronous Code

Testing asynchronous code with Mocha could not be simpler! Simply invoke the callback when your test is complete. By adding a callback (usually named `done`) to `it()`, Mocha will know that it should wait for this function to be called to complete the test.
Testing asynchronous code with Mocha could not be simpler! Simply invoke the callback when your test is complete. By adding a callback (usually named `done`) to `it()`, Mocha will know that it should wait for this function to be called to complete the test. This callback accepts both an `Error` instance, or `undefined`.

```js
describe('User', function() {
Expand All @@ -171,7 +171,7 @@ describe('User', function() {
});
```

To make things even easier, the `done()` callback accepts an error, so we may use this directly:
To make things even easier, the `done()` callback also accepts an `Error` instance (ie, `new Error()`), so we may use this directly:

```js
describe('User', function() {
Expand All @@ -184,6 +184,7 @@ describe('User', function() {
});
```


### Working with Promises

Alternately, instead of using the `done()` callback, you may return a [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise). This is useful if the APIs you are testing return promises instead of taking callbacks:
Expand Down

0 comments on commit 0a3569d

Please sign in to comment.