Skip to content

Files

Latest commit

 

History

History
31 lines (24 loc) · 613 Bytes

no-interpolation-in-snapshots.md

File metadata and controls

31 lines (24 loc) · 613 Bytes

Pattern: String interpolation in snapshot

Issue: -

Description

Using string interpolation in snapshots prevents them from being properly updated. Property matchers should be used instead to handle dynamic values in snapshots.

Examples

Example of incorrect code:

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

expect(error).toThrowErrorMatchingInlineSnapshot(`${message}`);

Example of correct code:

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