{"record":{"id":"c3f90a26cf261484","repo":"oxc-project/oxc","slug":"the-use-of-tobecalledtimes-1-and-tohavebeencal","errorCode":null,"errorMessage":"The use of `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` is discouraged.","messagePattern":"The use of `toBeCalledTimes\\(1\\)` and `toHaveBeenCalledTimes\\(1\\)` is discouraged\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_called_once.rs","lineNumber":13,"sourceCode":"use oxc_ast::{AstKind, ast::Argument};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    rule::Rule,\n    utils::{PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn prefer_called_once_diagnostic(span: Span, new_matcher_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"The use of `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` is discouraged.\",\n    )\n    .with_help(format!(\"Prefer `{new_matcher_name}()`.\"))\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferCalledOnce;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Substitute `toBeCalledTimes(1)` and `toHaveBeenCalledTimes(1)` with\n    /// `toBeCalledOnce()` and `toHaveBeenCalledOnce()` respectively.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// The `*Times` matchers require reading the argument to know how many","sourceCodeStart":1,"sourceCodeEnd":31,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_called_once.rs#L1-L31","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_once.rs:13 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `toBeCalledTimes(1)` / `toHaveBeenCalledTimes(1)` with `toHaveBeenCalledOnce()`"],"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-14T00:17:10.932Z"}