jest/prefer-hooks-in-order
eslint-plugin-jest
No autofix
eslint.config.js
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-hooks-in-order": "error",
},
},
];describe('foo', () => {
beforeEach(() => {
seedMyDatabase();
});
beforeAll(() => {
createMyDatabase();
});
it('accepts this input', () => {
// ...
});
it('returns that value', () => {
// ...
});
describe('when the database has specific values', () => {
const specificValue = '...';
beforeEach(() => {
seedMyDatabase(specificValue);
});
it('accepts that input', () => {
// ...
});
it('throws an error', () => {
// ...
});
// …describe('foo', () => {
beforeAll(() => {
createMyDatabase();
});
beforeEach(() => {
seedMyDatabase();
});
it('accepts this input', () => {
// ...
});
it('returns that value', () => {
// ...
});
describe('when the database has specific values', () => {
const specificValue = '...';
beforeEach(() => {
seedMyDatabase(specificValue);
});
it('accepts that input', () => {
// ...
});
it('throws an error', () => {
// ...
});
// …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/prefer-hooks-in-order
eslint-plugin-jest
import jest from "eslint-plugin-jest";
export default [
{
plugins: { jest },
rules: {
"jest/prefer-hooks-in-order": "error",
},
},
];jest/prefer-hooks-in-order
jest plugin · style
{
"plugins": [
"jest"
],
"rules": {
"jest/prefer-hooks-in-order": "error"
}
}style/useTestHooksInOrder
style · since 2.4.15
{
"linter": {
"rules": {
"style": {
"useTestHooksInOrder": "error"
}
}
}
}Enforce having hooks in consistent order
Suggest using the built-in equality matchers
Suggest having hooks before any test cases