no-duplicate-hooks
Configuration
rslint.config.ts
Rule Details
Disallow duplicate Jest lifecycle hooks in the same scope. Each describe block (including describe.skip, describe.each, and tagged describe.each) opens a new scope; registering the same hook name twice (beforeEach, afterEach, beforeAll, or afterAll) reports the second and later calls.
- Same scope: hooks directly in a
describecallback, or anywhere still inside thatdescribewhile it is active (including inside nestedtest/itbodies). - Separate scopes: nested
describeblocks; siblingdescribeblocks; file top level (hooks outside anydescribeshare one scope). - Allowed: one of each hook type in the same block; the same hook name again in a child or sibling
describe. - Imports:
@jest/globalshooks and renamed bindings (e.g.afterEach as somethingElse) count toward the same hook name.
Examples of incorrect code for this rule:
Examples of correct code for this rule: