close

no-interpolation-in-snapshots

Added in v0.8.0

Configuration

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

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

Rule Details

Disallows interpolation inside inline snapshots. Updating a snapshot rewrites the literal in the source file, so interpolated values can be silently lost.

Only toMatchInlineSnapshot and toThrowErrorMatchingInlineSnapshot are checked. Other snapshot matchers keep their expected value outside the source file and are not affected by snapshot updates in the same way.

Incorrect

expect(user).toMatchInlineSnapshot(`
  {
    "id": ${user.id},
  }
`);

Correct

expect(user).toMatchInlineSnapshot(`
  {
    "id": 1,
  }
`);

expect(user).toMatchInlineSnapshot({ id: expect.any(Number) });