oxc-project/oxc · error · OxcDiagnostic

Avoid having conditionals in tests

Error message

Avoid having conditionals in tests

What it means

Emitted by the vitest/no-conditional-tests rule at a conditional statement (`if`, ternary, switch, etc.) found inside a `test`/`it` body. Conditional logic in a test usually means some paths are silently skipped, weakening coverage; the rule demands unconditional tests or separate tests per path.

Source

Thrown at crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs:12

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{
    context::LintContext,
    rule::Rule,
    utils::{JestFnKind, JestGeneralFnKind, PossibleJestNode, is_type_of_jest_fn_call},
};

fn no_conditional_tests(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Avoid having conditionals in tests")
        .with_help("Remove the surrounding if statement.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoConditionalTests;

declare_oxc_lint!(
    /// ### 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.

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the surrounding if statement and always run the assertions
  2. Split the test into separate tests, one per branch
  3. Use `test.skip`/`test.skipIf` instead of runtime conditionals when skipping is intended
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vitest/no_conditional_tests.rs:12 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/b9b468002034c485. Report an issue: GitHub.