{"record":{"id":"abe75a7031c37660","repo":"oxc-project/oxc","slug":"use-tobecalledtimes-1-or-tohavebeencalledtimes","errorCode":null,"errorMessage":"Use `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` instead of `toBeCalledOnce()` or `toHaveBeenCalledOnce()`","messagePattern":"Use `toBeCalledTimes\\(1\\)` or `toHaveBeenCalledTimes\\(1\\)` instead of `toBeCalledOnce\\(\\)` or `toHaveBeenCalledOnce\\(\\)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_called_times.rs","lineNumber":17,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{\n    context::LintContext,\n    fixer::RuleFixer,\n    rule::Rule,\n    utils::{ParsedExpectFnCall, PossibleJestNode, parse_expect_jest_fn_call},\n};\nuse oxc_ast::{\n    AstKind,\n    ast::{Argument, CallExpression},\n};\n\nfn prefer_called_times_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Use `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` instead of `toBeCalledOnce()` or `toHaveBeenCalledOnce()`\")\n        .with_help(\"Replace with `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` for clarity and consistency\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferCalledTimes;\n\n// See <https://github.com/vitest-dev/eslint-plugin-vitest/blob/main/docs/rules/prefer-called-times.md> for rule details.\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// This rule aims to enforce the use of `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` over `toBeCalledOnce()` or `toHaveBeenCalledOnce()`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// This rule aims to enforce the use of `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` over `toBeCalledOnce()` or `toHaveBeenCalledOnce()`.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":35,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_called_times.rs#L1-L35","documentation":"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)`.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_times.rs:17 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `toBeCalledOnce()` / `toHaveBeenCalledOnce()` with `toBeCalledTimes(1)` or `toHaveBeenCalledTimes(1)` (a fix is provided)"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}