Skip to content

vitest/no-conditional-tests Correctness ​

✅ This rule is turned on by default.

What it does ​

The rule disallows the use of conditional statements within test cases to ensure that tests are deterministic and clearly readable.

Why is this bad? ​

Conditional statements in test cases can make tests unpredictable and harder to understand. Tests should be consistent and straightforward to ensure reliable results and maintainability.

Examples ​

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny vitest/no-conditional-tests --vitest-plugin
json
{
  "plugins": ["vitest"],
  "rules": {
    "vitest/no-conditional-tests": "error"
  }
}

References ​

Released under the MIT License.