# require-hook

Rule `jest/require-hook`. Require setup and teardown code to be within a hook

- Source: jest
- Technologies: Testing
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1763 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/require-hook` | no | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/require-hook.md) |
| Oxlint | `jest/require-hook` | no | no | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/require-hook.html) |

## Code examples

### Correct: the rule accepts this

```js
import { enableAutoDestroy, mount } from '@vue/test-utils';
import { initDatabase, tearDownDatabase } from './databaseUtils';

enableAutoDestroy(afterEach);

beforeEach(initDatabase);
afterEach(tearDownDatabase);

describe('Foo', () => {
  test('always returns 42', () => {
    expect(global.getAnswer()).toBe(42);
  });
});
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import jest from "eslint-plugin-jest";

export default [
  {
    plugins: { jest },
    rules: {
      "jest/require-hook": "error",
    },
  },
];
```

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/require-hook": "error"
  }
}
```

## Related rules

- [vitest/require-hook](https://lintradar.dev/rules/vitest/require-hook.md): Require setup and teardown to be within a hook
- [jest/prefer-todo](https://lintradar.dev/rules/jest/prefer-todo.md): Suggest using `test.todo`
- [jest/require-to-throw-message](https://lintradar.dev/rules/jest/require-to-throw-message.md): Require a message for `toThrow()`
- [jest/prefer-snapshot-hint](https://lintradar.dev/rules/jest/prefer-snapshot-hint.md): Prefer including a hint with external snapshots
- [jest/prefer-mock-return-shorthand](https://lintradar.dev/rules/jest/prefer-mock-return-shorthand.md): Prefer mock return shorthands
- [jest/prefer-mock-promise-shorthand](https://lintradar.dev/rules/jest/prefer-mock-promise-shorthand.md): Prefer mock resolved/rejected shorthands for promises

---

Web page: https://lintradar.dev/rules/jest/require-hook. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
