Skip to content

Files

Latest commit

 

History

History
29 lines (23 loc) · 571 Bytes

no-conditional-tests.md

File metadata and controls

29 lines (23 loc) · 571 Bytes

Pattern: Conditional test declarations

Issue: -

Description

Using conditional statements (like if blocks) around test cases makes tests unpredictable and harder to understand. Tests should be deterministic and straightforward to ensure reliable results and easier maintenance.

Examples

Example of incorrect code:

describe("my tests", () => {
  if (true) {
    it("is awesome", () => {
      doTheThing();
    });
  }
});

Example of correct code:

describe("my tests", () => {
  it("is awesome", () => {
    doTheThing();
  });
});