🚫 This rule is disabled in the ✅ recommended
config.
Mocha's tests or hooks (like before
) may be asynchronous by returning a Promise. When such a Promise-returning function is defined using an ES7 async
function it can be confusing when combined with an explicit return
of a Promise, as it's mixing the two styles.
This rule looks for every test and hook (before
, after
, beforeEach
and afterEach
) and reports when the function is async and returns a value. Returning a non-Promise value is fine from Mocha's perspective, though it is ignored, but helps the linter catch more error cases.
The following patterns are considered warnings:
describe('suite', function () {
before('title', async function () {
return foo;
});
it('title', async function () {
return bar().then(function () {
quux();
});
});
});
These patterns would not be considered warnings:
describe('suite', function () {
before('title', async function () {
await foo();
});
it('title', function () {
if (bailEarly) {
return;
}
await bar();
});
});
- If you use another library which exposes a similar API as mocha (e.g.
before
,after
), you should turn this rule off, because it would raise warnings.