{"record":{"id":"5d9a3804ce8b7f70","repo":"oxc-project/oxc","slug":"prefer-tohavebeencalledexactlyoncewith-over-toh","errorCode":null,"errorMessage":"Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` on the same target.","messagePattern":"Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` on the same target\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_called_exactly_once_with.rs","lineNumber":27,"sourceCode":"use oxc_span::{GetSpan, Span};\nuse oxc_str::CompactStr;\nuse std::collections::BTreeMap;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::Rule,\n    utils::{\n        KnownMemberExpressionProperty, ParsedExpectFnCall, ParsedJestFnCallNew, PossibleJestNode,\n        parse_jest_fn_call,\n    },\n};\n\nfn prefer_called_exactly_once_with_diagnostic(\n    substitute_span: Span,\n    remove_span: Span,\n) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `toHaveBeenCalledExactlyOnceWith` over `toHaveBeenCalledOnce` and `toHaveBeenCalledWith` on the same target.\")\n        .with_labels([\n            substitute_span.label(\"Replace with `toHaveBeenCalledExactlyOnceWith`\"),\n            remove_span.label(\"Remove this expect\"),\n        ])\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferCalledExactlyOnceWith;\n\n#[derive(Debug, Eq, PartialEq)]\nenum ExpectPairStates {\n    WaitingOnce,\n    WaitingWith,\n    Paired,\n}\n\n#[derive(Debug, Eq, PartialEq, Hash)]\nenum MatcherKind {","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_called_exactly_once_with.rs#L9-L45","documentation":"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.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_called_exactly_once_with.rs:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the two assertions with a single `expect(fn).toHaveBeenCalledExactlyOnceWith(...args)`"],"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"}