oxc-project/oxc · error · OxcDiagnostic

Enforces a maximum number assertion calls in a test body.

Error message

Enforces a maximum number assertion calls in a test body.

What it means

Raised by jest/max-expects when the number of assertion calls (expect(...)) in a single test body exceeds the configured maximum (default 5). Large assertion counts usually signal a test doing too much.

Source

Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/max_expects.rs:15

use rustc_hash::FxHashMap;
use schemars::JsonSchema;
use serde::Deserialize;

use oxc_ast::{AstKind, ast::Expression};
use oxc_diagnostics::OxcDiagnostic;
use oxc_span::Span;

use crate::{
    context::LintContext,
    utils::{PossibleJestNode, collect_possible_jest_call_node},
};

fn exceeded_max_assertion(count: u32, max: u32, span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Enforces a maximum number assertion calls in a test body.")
        .with_help(format!("Too many assertion calls ({count}) - maximum allowed is {max}"))
        .with_label(span)
}

pub const DOCUMENTATION: &str = r"### What it does

This rule enforces a maximum number of `expect()` calls in a single test.

### Why is this bad?

Tests with many different assertions are likely mixing multiple objectives.
It is generally better to have a single objective per test to ensure that when a test fails,
the problem is easy to identify.

### Examples

Examples of **incorrect** code for this rule:
```javascript

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Split the test into smaller focused tests with fewer assertions.
  2. Raise or configure the max option if the count is intentional.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/max_expects.rs:15 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/3bdd8c932a88c27d. Report an issue: GitHub.