{"record":{"id":"1eaeb5e881072b82","repo":"oxc-project/oxc","slug":"prefix-hasassertions-expects-no-arguments","errorCode":null,"errorMessage":"`{prefix}.hasAssertions` expects no arguments.","messagePattern":"`(.+?)\\.hasAssertions` expects no arguments\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs","lineNumber":168,"sourceCode":"test('callback test', () => {\n  expect.assertions(1);\n  fetchData((data) => {\n    expect(data).toBe('peanut butter');\n  });\n});\n```\n\"#;\n\nfn expect_shadowed_by_parameter(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"`expect` is shadowed by a callback parameter and cannot be used for assertions.\",\n    )\n    .with_help(\"Rename the parameter to avoid shadowing the global `expect`.\")\n    .with_label(span)\n}\n\npub fn has_assertions_takes_no_arguments(span: Span, prefix: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"`{prefix}.hasAssertions` expects no arguments.\"))\n        .with_help(format!(\"Remove the arguments from `{prefix}.hasAssertions()`.\"))\n        .with_label(span)\n}\n\nfn assertions_requires_one_argument(span: Span, prefix: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"`{prefix}.assertions` expects a single argument of type number.\"))\n        .with_help(format!(\"Pass a single numeric argument to `{prefix}.assertions()`.\"))\n        .with_label(span)\n}\n\nfn assertions_requires_number_argument(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"This argument should be a number.\")\n        .with_help(\"Replace this argument with a numeric literal.\")\n        .with_label(span)\n}\n\npub fn resolve_expect_local_name(ctx: &LintContext<'_>, sources: &[&str]) -> CompactStr {\n    for entry in &ctx.module_record().import_entries {","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs#L150-L186","documentation":"From the oxlint `prefer-expect-assertions` rule family (these helpers are shared/public in prefer_expect_assertions.rs): `expect.hasAssertions()` verifies that at least one assertion ran during the test and takes no arguments by design. Passing any argument is a misuse the linter reports immediately, because the argument is silently ignored at runtime.","triggerScenarios":"A member call on the resolved expect prefix whose member name is `hasAssertions` and whose argument list is non-empty: `expect.hasAssertions(1)`, `expect.hasAssertions('one')`, or the same via a file-level imported alias (e.g. `myExpect.hasAssertions(x)`).","commonSituations":"Copy-paste from `expect.assertions(2)` where the developer changed the member name but left the count; assuming hasAssertions means 'require N assertions'; autocomplete inserting the wrong member with existing parens content.","solutions":["Delete the argument: use `expect.hasAssertions()`.","If you actually meant to require a specific count, use `expect.assertions(n)` with a single numeric literal instead."],"exampleFix":"// before\nit('syncs', () => {\n  expect.hasAssertions(2);\n  doSync();\n  expect(synced).toBe(true);\n});\n\n// after\nit('syncs', () => {\n  expect.hasAssertions();\n  doSync();\n  expect(synced).toBe(true);\n});","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{ \"rules\": { \"jest/prefer-expect-assertions\": \"error\" } }\n\nnpx oxlint tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["hasAssertions is a zero-argument flag; assertions(n) is the counting form — do not mix them.","When converting between the two, delete the parens content rather than editing around it."],"tags":["jest","vitest","oxlint","testing","assertions","api-misuse","static-analysis"],"backgroundTag":"expect-assertions-argument-misuse","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"}