Skip to content

armgit / mocha

Public Imported from GitHub
0

☕️ Classic, reliable, trusted test framework for Node.js and the browser

Add section about ES6 arrow functions

Michiel de Jong2a91194f74ba
diff --git a/index.md b/index.md
index eb2a7b19..4c96c69e 100644
--- a/index.md
+++ b/index.md
@@ -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)
@@ -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.