Title here
Summary here
Mocha proposes hooks that allow code to be run before or after every or all tests. This helps define a common setup or teardown process for every test. These hooks should only be declared inside test suites, as they would otherwise be run before or after every test or test suite of the project, even if the test suite of the file they were declared in was skipped. This can lead to very confusing and unwanted effects.
This rule looks for every call to before
, after
, beforeEach
and afterEach
that are not in a test suite.
before(function () { /* ... */ }); // Not allowed
after(function () { /* ... */ }); // Not allowed
beforeEach(function () { /* ... */ }); // Not allowed
afterEach(function () { /* ... */ }); // Not allowed
describe('foo', function () {
before(function () { /* ... */ });
after(function () { /* ... */ });
beforeEach(function () { /* ... */ });
afterEach(function () { /* ... */ });
});