jest/no-hooks
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-hooks": "error",
},
},
];function setupFoo(options) {
/* ... */
}
function setupBar(options) {
/* ... */
}
describe('foo', () => {
let foo;
beforeEach(() => {
foo = setupFoo();
});
afterEach(() => {
foo = null;
});
it('does something', () => {
expect(foo.doesSomething()).toBe(true);
});
describe('with bar', () => {
let bar;
beforeEach(() => {
bar = setupBar();
});
afterEach(() => {
bar = null;
// …function setupFoo(options) {
/* ... */
}
function setupBar(options) {
/* ... */
}
describe('foo', () => {
it('does something', () => {
const foo = setupFoo();
expect(foo.doesSomething()).toBe(true);
});
it('does something with bar', () => {
const foo = setupFoo();
const bar = setupBar();
expect(foo.doesSomething(bar)).toBe(true);
});
});Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
jest/no-hooks
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/no-hooks": "error",
},
},
];jest/no-hooks
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/no-hooks": "error"
}
}nursery/noTestHooks
nursery · since 2.6.9
{
"linter": {
"rules": {
"nursery": {
"noTestHooks": "error"
}
}
}
}Enforces a maximum depth to nested describe calls
Suggest using the built-in equality matchers
Prefer having hooks in a consistent order