oxc-project/oxc · warning
`toMatchSnapshot` takes at most two arguments.
Error message
`toMatchSnapshot` takes at most two arguments.
What it means
This is the oxlint `prefer-snapshot-hint` rule (jest/vitest plugin), argument-count branch. `toMatchSnapshot()` accepts at most two arguments — a hint string, or a property-matcher object followed by a hint string. Passing three or more is always a bug (extra args are ignored), so the linter rejects it outright before even considering the hint policy.
Source
Thrown at crates/oxc_linter/src/rules/shared/jest_vitest/prefer_snapshot_hint.rs:22
use oxc_ast::{
AstKind,
ast::{CallExpression, Expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_semantic::NodeId;
use oxc_span::Span;
use crate::{
context::LintContext,
utils::{
JestFnKind, JestGeneralFnKind, PossibleJestNode, collect_possible_jest_call_node,
parse_expect_jest_fn_call,
},
};
fn snapshot_matcher_too_many_arguments_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("`toMatchSnapshot` takes at most two arguments.")
.with_help("Pass a hint string, or a property matcher object followed by a hint string.")
.with_label(span)
}
fn snapshot_missing_hint_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Snapshot is missing a hint.")
.with_help("Include a hint string to identify this snapshot in the snapshot file.")
.with_label(span)
}
fn snapshot_hint_must_be_string_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Snapshot hint must be a string literal.")
.with_help(
"Provide a string literal as the hint, or pass a property matcher object as the first argument and the hint string as the second.",
)
.with_label(span)
}
View on GitHub (pinned to e1e7af627c)
Solutions
- Reduce to the two valid forms: `toMatchSnapshot('my hint')` or `toMatchSnapshot(propertyMatchers, 'my hint')`.
- Delete leftover arguments that were meaningful in another matcher but not here.
Example fix
// before
expect(user).toMatchSnapshot({ createdAt: expect.any(Date) }, 'saved user', true);
// after
expect(user).toMatchSnapshot({ createdAt: expect.any(Date) }, 'saved user'); Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{ "rules": { "jest/prefer-snapshot-hint": "error" } }
npx oxlint tests/ Prevention
- Learn the two-argument ceiling: hint, or (propertyMatchers, hint) — nothing else.
- Delete stale arguments when converting matchers instead of carrying them over.
When it happens
Trigger: A `toMatchSnapshot` matcher call (recognized via `parse_expect_jest_fn_call` member scan) with `arguments.len() > 2`, in a scope that the mode (`multi`) requires hints for — e.g. `expect(x).toMatchSnapshot({}, 'hint', 'extra')`.
Common situations: Chaining legacy calls that accumulated arguments over time; misunderstanding the property-matcher + hint signature; refactoring from inline snapshots that carried extra flags.
Related errors
- Snapshot hint must be a string literal.
- `{prefix}.hasAssertions` expects no arguments.
- `{prefix}.assertions` expects a single argument of type numb
- This argument should be a number.
- Snapshot is missing a hint.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/17e19bd5423419d4.
Report an issue: GitHub.