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. It is possible to declare a hook multiple times inside the same test suite, but it can be confusing. It is better to have one hook handle the whole of the setup or teardown logic of the test suite.
This rule looks for every call to before
, after
, beforeEach
and afterEach
and reports them if they are called at least twice inside a test suite at the same level.
describe('foo', function () {
var mockUser;
var mockLocation;
before(function () { // Is allowed this time
mockUser = {age: 50};
});
before(function () { // Duplicate! Is not allowed this time
mockLocation = {city: 'New York'};
});
// Same for the other hooks
after(function () {});
after(function () {}); // Duplicate!
beforeEach(function () {});
beforeEach(function () {}); // Duplicate!
afterEach(function () {});
afterEach(function () {}); // Duplicate!
});
describe('foo', function () {
var mockUser;
var mockLocation;
before(function () { // Is allowed this time
mockUser = {age: 50};
mockLocation = {city: 'New York'};
});
describe('bar', function () {
before(function () { // Is allowed because it's nested in a new describe
// ...
});
});
});