For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt, and this page is available as Markdown at https://rslint.rs/rules/jest/no-interpolation-in-snapshots.md.
close

no-interpolation-in-snapshots

Added in v0.7.0

Configuration

PresetConfigured Value
✅ jestPlugin.configs.all"error"
✅ jestPlugin.configs.recommended"error"
rslint.config.ts
import { defineConfig, jestPlugin } from '@rslint/core';

export default defineConfig([
  jestPlugin.configs.recommended,
  {
    rules: {
      'jest/no-interpolation-in-snapshots': 'error',
    },
  },
]);

Rule Details

Disallow string interpolation inside inline snapshots. Interpolation prevents Jest from updating snapshots; instead, overload dynamic properties with a matcher via property matchers.

Examples of incorrect code for this rule:

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

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

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

Examples of correct code for this rule:

expect(something).toMatchInlineSnapshot();

expect(something).toMatchInlineSnapshot(
  `Object {
    property: 1
  }`,
);

expect(something).toMatchInlineSnapshot(
  { property: expect.any(Date) },
  `Object {
    property: Any<Date>
  }`,
);

expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot();

expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
  `Error Message`,
);

Original Documentation