Skip to content
← Back to rules

jest/no-interpolation-in-snapshots Style

What it does

Prevents the use of string interpolations in snapshots.

Why is this bad?

Interpolation prevents snapshots from being updated. Instead, properties should be overloaded with a matcher by using property matchers.

Examples

Examples of incorrect code for this rule:

javascript
expect(something).toMatchInlineSnapshot(
  `Object {
    property: ${interpolated}
  }`,
);

expect(something).toMatchInlineSnapshot(
  { other: expect.any(Number) },
  `Object {
    other: Any<Number>,
    property: ${interpolated}
  }`,
);

expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(`${interpolated}`);

How to use

To enable this rule using the config file or in the CLI, you can use:

json
{
  "plugins": ["jest"],
  "rules": {
    "jest/no-interpolation-in-snapshots": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["jest"],
  rules: {
    "jest/no-interpolation-in-snapshots": "error",
  },
});
bash
oxlint --deny jest/no-interpolation-in-snapshots --jest-plugin

Version

This rule was added in v0.0.13.

References