ES6 arrows vs Mocha
ES6 arrow functions have static, lexical this
binding. This is a great
feature, but it prevents them from playing nicely with Mocha, because
Mocha provides the test context using dynamic this
binding:
This will not work for arrow functions:
// undefined, `this` points to the global object
This little library provides a set of patched Mocha functions (it
,
before
, after
, beforeEach
and afterEach
) that pass the context
as the first argument to your arrows:
// MyAwesomeThing {}
This is done by wrapping each arrow into the usual function, obtaining the
context through this
and passing it to the first argument of the arrow.
Example
// This line is important, otherwise the magic will not work!// Is is commented because it breaks GitHub syntax highlighting.//// import { it, before, after, beforeEach, afterEach } from 'arrow-mocha'
License
MIT