{"record":{"id":"c06f659cf7c72155","repo":"oxc-project/oxc","slug":"this-test-should-have-either-prefix-assertions","errorCode":null,"errorMessage":"This test should have either `{prefix}.assertions(<number of assertions>)` or `{prefix}.hasAssertions()` as its first expression.","messagePattern":"This test should have either `(.+?)\\.assertions\\(<number of assertions>\\)` or `(.+?)\\.hasAssertions\\(\\)` as its first expression\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/vitest/prefer_expect_assertions.rs","lineNumber":27,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::Span;\nuse oxc_str::CompactStr;\n\nuse crate::{\n    context::LintContext,\n    fixer::RuleFix,\n    rule::{DefaultRuleConfig, Rule},\n    rules::shared::prefer_expect_assertions::{\n        CallbackBody, DOCUMENTATION, PreferExpectAssertionsConfig, PreferExpectAssertionsRuleImpl,\n        resolve_expect_local_name, should_check,\n    },\n    utils::{collect_possible_jest_call_node, get_node_name},\n};\n\nfn have_expect_assertions(span: Span, prefix: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\n        \"This test should have either `{prefix}.assertions(<number of assertions>)` or `{prefix}.hasAssertions()` as its first expression.\",\n    ))\n    .with_help(format!(\"Add `{prefix}.hasAssertions()` or `{prefix}.assertions(<number>)` as the first statement in this test.\"))\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, Deserialize)]\npub struct PreferExpectAssertions(Box<PreferExpectAssertionsConfig>);\n\nimpl std::ops::Deref for PreferExpectAssertions {\n    type Target = PreferExpectAssertionsConfig;\n\n    fn deref(&self) -> &Self::Target {\n        &self.0\n    }\n}\n\ndeclare_oxc_lint!(","sourceCodeStart":9,"sourceCodeEnd":45,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/vitest/prefer_expect_assertions.rs#L9-L45","documentation":"Emitted by the vitest/prefer-expect-assertions rule when a test body neither begins with `expect.assertions(n)` nor `expect.hasAssertions()`. The rule enforces an explicit assertion-count guard at the start of each test so silently passing tests with zero assertions are caught.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/vitest/prefer_expect_assertions.rs:27 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Add `expect.assertions(n)` as the first expression of the test, where n is the number of expected assertions","Or add `expect.hasAssertions()` as the first expression"],"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"}