oxc-project/oxc · error · OxcDiagnostic
The use of `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1
Error message
The use of `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` is discouraged.
What it means
Emitted by the vitest/prefer-called-once rule at an expectation using `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)`. It fires because asserting exactly one call is better written with the dedicated `toHaveBeenCalledOnce()` matcher, which is clearer and gives better failure messages.
Source
Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_once.rs:13
use oxc_ast::{AstKind, ast::Argument};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use crate::{
context::LintContext,
rule::Rule,
utils::{PossibleJestNode, parse_expect_jest_fn_call},
};
fn prefer_called_once_diagnostic(span: Span, new_matcher_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(
"The use of `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` is discouraged.",
)
.with_help(format!("Prefer `{new_matcher_name}()`."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct PreferCalledOnce;
declare_oxc_lint!(
/// ### What it does
///
/// Substitute `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` with
/// `toBeCalledOnce()` and `toHaveBeenCalledOnce()` respectively.
///
/// ### Why is this bad?
///
/// The `*Times` matchers require reading the argument to know how manyView on GitHub (pinned to e1e7af627c)
Solutions
- Replace `toBeCalledTimes(1)` / `toHaveBeenCalledTimes(1)` with `toHaveBeenCalledOnce()`
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_once.rs:13 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/c3f90a26cf261484.
Report an issue: GitHub.