Skip to content

Files

Latest commit

 

History

History
39 lines (29 loc) · 692 Bytes

no-confusing-set-timeout.md

File metadata and controls

39 lines (29 loc) · 692 Bytes

Pattern: Misplaced setTimeout call

Issue: -

Description

Calling jest.setTimeout() anywhere other than in global scope can lead to confusing behavior. The timeout should not be called multiple times or after Jest functions like hooks, describe, or test.

Examples

Example of incorrect code:

describe("test suite", () => {
  jest.setTimeout(1000);
  
  it("test case", () => {
    // test logic
  });
});

test("foo", () => {
  jest.setTimeout(1000);
});

beforeEach(() => {
  jest.setTimeout(1000);
});

Example of correct code:

jest.setTimeout(1000);

describe("test suite", () => {
  it("test case", () => {
    // test logic
  });
});