# jest/no-duplicate-hooks

> Disallow using the same hook twice in one `describe` block

Two `beforeEach` calls in the same block both run, so nothing fails. But someone who reads the first one assumes that's all the setup and misses the second, which can be many lines below.

Hooks are counted per `describe` block, and the top level of the file counts as a block. A nested `describe` can have its own `beforeEach`.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"jest/no-duplicate-hooks" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad */}
```ts
import { beforeEach, describe, test } from "@jest/globals";

describe("cart", () => {
  beforeEach(() => {
    cart.clear();
  });

  test("starts empty", () => {});

  beforeEach(() => {
    cart.add("apple");
  });
});
```

Not reported:

{/* good */}
```ts
import { beforeEach, describe, test } from "@jest/globals";

describe("cart", () => {
  beforeEach(() => {
    cart.clear();
    cart.add("apple");
  });

  test("has one item", () => {});

  describe("after checkout", () => {
    beforeEach(() => {
      cart.checkout();
    });

    test("is empty", () => {});
  });
});
```
