Skip to content

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.

Example

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

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

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

References

Released under the MIT License.