oxc-project/oxc · warning
`{prefix}.hasAssertions` expects no arguments.
Error message
`{prefix}.hasAssertions` expects no arguments. What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/prefer_expect_assertions.rs:168
test('callback test', () => {
expect.assertions(1);
fetchData((data) => {
expect(data).toBe('peanut butter');
});
});
```
"#;
fn expect_shadowed_by_parameter(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn(
"`expect` is shadowed by a callback parameter and cannot be used for assertions.",
)
.with_help("Rename the parameter to avoid shadowing the global `expect`.")
.with_label(span)
}
pub fn has_assertions_takes_no_arguments(span: Span, prefix: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{prefix}.hasAssertions` expects no arguments."))
.with_help(format!("Remove the arguments from `{prefix}.hasAssertions()`."))
.with_label(span)
}
fn assertions_requires_one_argument(span: Span, prefix: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("`{prefix}.assertions` expects a single argument of type number."))
.with_help(format!("Pass a single numeric argument to `{prefix}.assertions()`."))
.with_label(span)
}
fn assertions_requires_number_argument(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("This argument should be a number.")
.with_help("Replace this argument with a numeric literal.")
.with_label(span)
}
pub fn resolve_expect_local_name(ctx: &LintContext<'_>, sources: &[&str]) -> CompactStr {
for entry in &ctx.module_record().import_entries {View on GitHub (pinned to e1e7af627c)
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.
Example fix
// before
it('syncs', () => {
expect.hasAssertions(2);
doSync();
expect(synced).toBe(true);
});
// after
it('syncs', () => {
expect.hasAssertions();
doSync();
expect(synced).toBe(true);
}); Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{ "rules": { "jest/prefer-expect-assertions": "error" } }
npx oxlint tests/ Prevention
- 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.
When it happens
Trigger: 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)`).
Common situations: 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.
Related errors
- `{prefix}.assertions` expects a single argument of type numb
- This argument should be a number.
- `expect` must be inside of a test block.
- Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()`
- Suggest using the built-in equality matchers.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/1eaeb5e881072b82.
Report an issue: GitHub.