jest/no-duplicate-hooks
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-duplicate-hooks": "error",
},
},
];describe('foo', () => {
beforeEach(() => {
// some setup
});
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
});
// Nested describe scenario
describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
describe('bar', () => {
test('bar_test', () => {
afterAll(() => {
// some teardown
});
afterAll(() => {
// some teardown
});
});
});
});describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
});
// Nested describe scenario
describe('foo', () => {
beforeEach(() => {
// some setup
});
test('foo_test', () => {
// some test
});
describe('bar', () => {
test('bar_test', () => {
beforeEach(() => {
// some setup
});
});
});
});Examples from the ESLint documentation.
jest/no-duplicate-hooks
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-duplicate-hooks": "error",
},
},
];jest/no-duplicate-hooks
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/no-duplicate-hooks": "error"
}
}suspicious/noDuplicateTestHooks
suspicious · since 1.6.0
{
"linter": {
"rules": {
"suspicious": {
"noDuplicateTestHooks": "error"
}
}
}
}Disallow duplicate hooks and teardown hooks
Disallow explicitly returning from tests
Enforce assertion to be made in a test body
Disallow calling expect conditionally