no-interpolation-in-snapshots
Added in v0.8.0Configuration
Rule Details
Disallow string interpolation inside inline snapshots. The expected value of an inline snapshot lives in the source file, and updating snapshots rewrites that literal — so the interpolation is evaluated away and silently lost. Overload dynamic properties with a property matcher instead.
Examples of incorrect code for this rule:
Examples of correct code for this rule:
Only inline snapshots are checked
The rule covers toMatchInlineSnapshot and toThrowErrorMatchingInlineSnapshot only. Every other snapshot matcher keeps its expected value outside the source file, so nothing rewrites its arguments and interpolation is harmless:
toMatchSnapshotand its Chai-style aliasmatchSnapshottoThrowErrorMatchingSnapshottoMatchFileSnapshot
toMatchFileSnapshot deserves a special mention: it has no Jest counterpart, and its first argument is a file path, so interpolating it is the intended usage rather than a mistake.