Skip to content

Files

Latest commit

 

History

History
39 lines (31 loc) · 682 Bytes

no-duplicate-hooks.md

File metadata and controls

39 lines (31 loc) · 682 Bytes

Pattern: Duplicate hook

Issue: -

Description

Using multiple instances of the same hook (beforeEach, afterEach, etc.) within a describe block creates confusion and may lead to unexpected behavior. Each hook type should only be used once per scope.

Examples

Example of incorrect code:

describe("suite", () => {
  beforeEach(() => {
    setup1();
  });
  beforeEach(() => {
    setup2();
  });
  
  test("foo", () => {
    expect(value).toBe(true);
  });
});

Example of correct code:

describe("suite", () => {
  beforeEach(() => {
    setup1();
    setup2();
  });
  
  test("foo", () => {
    expect(value).toBe(true);
  });
});