oxc-project/oxc · error · OxcDiagnostic
Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCal
Error message
Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` on the same target.
What it means
Emitted by the vitest/prefer-called-exactly-once-with rule when the same expect target is asserted with both `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` in one test body. The combination duplicates intent; `toHaveBeenCalledExactlyOnceWith` expresses it in a single atomic assertion.
Source
Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_exactly_once_with.rs:27
use oxc_span::{GetSpan, Span};
use oxc_str::CompactStr;
use std::collections::BTreeMap;
use crate::{
AstNode,
context::LintContext,
rule::Rule,
utils::{
KnownMemberExpressionProperty, ParsedExpectFnCall, ParsedJestFnCallNew, PossibleJestNode,
parse_jest_fn_call,
},
};
fn prefer_called_exactly_once_with_diagnostic(
substitute_span: Span,
remove_span: Span,
) -> OxcDiagnostic {
OxcDiagnostic::warn("Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` on the same target.")
.with_labels([
substitute_span.label("Replace with `toHaveBeenCalledExactlyOnceWith`"),
remove_span.label("Remove this expect"),
])
}
#[derive(Debug, Default, Clone)]
pub struct PreferCalledExactlyOnceWith;
#[derive(Debug, Eq, PartialEq)]
enum ExpectPairStates {
WaitingOnce,
WaitingWith,
Paired,
}
#[derive(Debug, Eq, PartialEq, Hash)]
enum MatcherKind {View on GitHub (pinned to e1e7af627c)
Solutions
- Replace the two assertions with a single `expect(fn).toHaveBeenCalledExactlyOnceWith(...args)`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_exactly_once_with.rs:27 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/5d9a3804ce8b7f70.
Report an issue: GitHub.