Skip to content

Commit

Permalink
Add section about ES6 arrow functions
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong authored and Michiel de Jong committed Dec 16, 2015
1 parent adf5afa commit 2a91194
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.md
Expand Up @@ -49,6 +49,7 @@ Mocha is a feature-rich JavaScript test framework running on [Node.js](http://no
- [Assertions](#assertions)
- [Synchronous Code](#synchronous-code)
- [Asynchronous Code](#asynchronous-code)
- [Arrow Functions](#arrow-functions)
- [Hooks](#hooks)
- [Pending Tests](#pending-tests)
- [Exclusive Tests](#exclusive-tests)
Expand Down Expand Up @@ -187,6 +188,10 @@ describe('#find()', function() {

(The latter example uses [Chai as Promised](https://www.npmjs.com/package/chai-as-promised) for fluent promise assertions.)

## Arrow functions

Passing [arrow functions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions) to Mocha is discouraged. Their lexical binding of the `this` value makes them unable to access the Mocha context, and statements like `this.timeout(1000);` will not work inside an arrow function.

## Hooks

Mocha provides the hooks `before()`, `after()`, `beforeEach()`, and `afterEach()`, which can be used to set up preconditions and clean up after your tests.
Expand Down

0 comments on commit 2a91194

Please sign in to comment.