oxc-project/oxc · error · OxcDiagnostic

Use `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` inste

Error message

Use `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` instead of `toBeCalledOnce()` or `toHaveBeenCalledOnce()`

What it means

Emitted by the vitest/prefer-called-times rule at an expectation using the `toBeCalledOnce()` or `toHaveBeenCalledOnce()` matcher. It fires because under this rule's convention call counts should be asserted with the explicit numeric form `toBeCalledTimes(1)` / `toHaveBeenCalledTimes(1)`.

Source

Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_times.rs:17

use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{
    context::LintContext,
    fixer::RuleFixer,
    rule::Rule,
    utils::{ParsedExpectFnCall, PossibleJestNode, parse_expect_jest_fn_call},
};
use oxc_ast::{
    AstKind,
    ast::{Argument, CallExpression},
};

fn prefer_called_times_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` instead of `toBeCalledOnce()` or `toHaveBeenCalledOnce()`")
        .with_help("Replace with `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` for clarity and consistency")
        .with_label(span)
}

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

// See <https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-called-times.md> for rule details.
declare_oxc_lint!(
    /// ### What it does
    ///
    /// This rule aims to enforce the use of `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` over `toBeCalledOnce()` or `toHaveBeenCalledOnce()`.
    ///
    /// ### Why is this bad?
    ///
    /// This rule aims to enforce the use of `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` over `toBeCalledOnce()` or `toHaveBeenCalledOnce()`.
    ///
    /// ### Examples

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Replace `toBeCalledOnce()` / `toHaveBeenCalledOnce()` with `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` (a fix is provided)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_times.rs:17 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/abe75a7031c37660. Report an issue: GitHub.