# no-hooks

Rule `jest/no-hooks`. Disallow setup and teardown hooks

- 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: #1661 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `jest/no-hooks` | no | no | package `eslint-plugin-jest` | [docs](https://github.com/jest-community/eslint-plugin-jest/blob/v29.17.2/docs/rules/no-hooks.md) |
| Oxlint | `jest/no-hooks` | no | no | plugin `jest`, category style | [docs](https://oxc.rs/docs/guide/usage/linter/rules/jest/no-hooks.html) |
| Biome | `nursery/noTestHooks` | no | no | group nursery, since 2.6.9 | [docs](https://biomejs.dev/linter/rules/no-test-hooks/) |

## Code examples

### Incorrect: the rule reports this

```js
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;
// …
```

### Correct: the rule accepts this

```js
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.

## Enable it

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

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

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

### Oxlint: `.oxlintrc.json`

```json
{
  "plugins": [
    "jest"
  ],
  "rules": {
    "jest/no-hooks": "error"
  }
}
```

### Biome: `biome.json`

```json
{
  "linter": {
    "rules": {
      "nursery": {
        "noTestHooks": "error"
      }
    }
  }
}
```

## Related rules

- [vitest/no-hooks](https://lintradar.dev/rules/vitest/no-hooks.md): Disallow setup and teardown hooks
- [jest/max-nested-describe](https://lintradar.dev/rules/jest/max-nested-describe.md): Enforces a maximum depth to nested describe calls
- [jest/prefer-called-with](https://lintradar.dev/rules/jest/prefer-called-with.md): Suggest using `toHaveBeenCalledWith()`
- [jest/consistent-test-it](https://lintradar.dev/rules/jest/consistent-test-it.md): Enforce `test` and `it` usage conventions
- [jest/prefer-equality-matcher](https://lintradar.dev/rules/jest/prefer-equality-matcher.md): Suggest using the built-in equality matchers
- [jest/prefer-hooks-in-order](https://lintradar.dev/rules/jest/prefer-hooks-in-order.md): Prefer having hooks in a consistent order

---

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