Currently functions that use () => cannot take advantage of the mocha context: http://mochajs.org/#arrow-functions.
However, arrow function usage could be improved by passing the context as an argument:
it('should do something cool', (done, context) => {
context.timeout = 5000;
...
});
The complicating factor is the done argument. The presence of which makes the test async. Perhaps if you want to use the context argument then you need to also call done when appropriate.
function () { this.timeout = 5000; } is less typing than (done, context) => { context.timeout = 5000; }
Forcing the function to be async to enable people to access the context seems like a pretty annoying API.
I still have no clue why people want to use arrow functions when it explicitly does the wrong thing in mochas context
Came here for this, but I've also found https://github.com/skozin/arrow-mocha
Here is a version which can work with mocha's --require option:
https://www.npmjs.com/package/mocha-context
@alexreardon thanks for the suggestion, You can always do the following as well:
it('some case', () => {
expect(1 + 2).to.equal(3);
}).timeout(1000);
Replacing the default bdd interface with this is a non-starter.
It's possible to create an interface which passes the context as the first parameter, but would likely require modifications to Mocha's core to support, due to hardcoded assumptions.
Would accept a PR that would allow the "async check" of an interface to be configurable. Once that's ready, then it should be fairly trivial to provide an alternate interface.
allow the "async check" of an interface to be configurable.
What does it mean?
I think this feature could be implemented in 2 ways:
bdd-arrow that would decorate the arrow function before sending fn to new Test.mocha --context-argument that would change how runnable.fn is called.@eight04 see #3399