{"record":{"id":"f1631088d4d7808a","repo":"oxc-project/oxc","slug":"do-not-use-string-interpolation-inside-of-snapshot","errorCode":null,"errorMessage":"Do not use string interpolation inside of snapshots","messagePattern":"Do not use string interpolation inside of snapshots","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/shared/jest_vitest/no_interpolation_in_snapshots.rs","lineNumber":11,"sourceCode":"use oxc_ast::{AstKind, ast::Argument};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_span::Span;\n\nuse crate::{\n    context::LintContext,\n    utils::{PossibleJestNode, parse_expect_jest_fn_call},\n};\n\nfn no_interpolation_in_snapshots_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use string interpolation inside of snapshots\")\n        .with_help(\"Remove string interpolation from snapshots\")\n        .with_label(span)\n}\n\npub const DOCUMENTATION: &str = r\"### What it does\n\nPrevents the use of string interpolations in snapshots.\n\n### Why is this bad?\n\nInterpolation prevents snapshots from being updated. Instead, properties should\nbe overloaded with a matcher by using\n[property matchers](https://jestjs.io/docs/en/snapshot-testing#property-matchers).\n\n### Examples\n\nExamples of **incorrect** code for this rule:\n```javascript","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/shared/jest_vitest/no_interpolation_in_snapshots.rs#L1-L29","documentation":"Diagnostic from oxlint rule `jest/no-interpolation-in-snapshots` (shared with vitest) in crates/oxc_linter/src/rules/shared/jest_vitest/no_interpolation_in_snapshots.rs:11. Snapshot arguments must be static: when a template literal passed to a snapshot matcher contains `${}` interpolation, Jest refuses to update the snapshot. The rule tells you to remove the interpolation and overload the dynamic value with a matcher instead.","triggerScenarios":"An expect() snapshot call (parsed via parse_expect_jest_fn_call) whose Argument is a template literal containing substitutions, e.g. expect(x).toMatchSnapshot(`${Date.now()}`) or toThrowErrorMatchingSnapshot(`error ${code}`).","commonSituations":"Trying to embed timestamps, ids, or counts in snapshot names/bodies; migrating tests where inline values were templated; misunderstanding that external snapshots are keyed by static names and inline snapshots must be writable.","solutions":["Move the dynamic value out of the snapshot and assert it separately: expect(x.timestamp).toEqual(expectedTs) alongside a static snapshot","Replace the whole snapshot with targeted matchers (toMatchObject / toHaveProperty) when most of the content is dynamic","Use a static descriptive string for the snapshot name and serialize dynamic parts into the object under a matcher placeholder (serializerAny in Vitest / expect.any in Jest)"],"exampleFix":"// before\nexpect(user).toMatchSnapshot(`user ${user.id}`);\n\n// after\nexpect(user.id).toBe(42);\nexpect({ ...user, id: expect.any(Number) }).toMatchSnapshot();","handlingStrategy":"validation","validationCode":"rg -n \"(?:toMatch|toThrowErrorMatching)(?:Inline)?Snapshot\\(\\`[^\\`]*\\$\\{\" tests/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep snapshot arguments static strings or omit them","Assert dynamic values (ids, timestamps) with dedicated matchers before snapshotting","Use expect.any(Number) / property matchers to absorb nondeterminism"],"tags":["jest","vitest","oxlint","testing","snapshots","interpolation","template-literal"],"backgroundTag":"snapshot-interpolation","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"}