source: frontend/node_modules/eslint-plugin-jest/docs/rules/no-interpolation-in-snapshots.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
Line 
1# Disallow string interpolation inside snapshots (`no-interpolation-in-snapshots`)
2
3Prevents the use of string interpolations in snapshots.
4
5## Rule Details
6
7Interpolation prevents snapshots from being updated. Instead, properties should
8be overloaded with a matcher by using
9[property matchers](https://jestjs.io/docs/en/snapshot-testing#property-matchers).
10
11Examples of **incorrect** code for this rule:
12
13```js
14expect(something).toMatchInlineSnapshot(
15 `Object {
16 property: ${interpolated}
17 }`,
18);
19
20expect(something).toMatchInlineSnapshot(
21 { other: expect.any(Number) },
22 `Object {
23 other: Any<Number>,
24 property: ${interpolated}
25 }`,
26);
27
28expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
29 `${interpolated}`,
30);
31```
32
33Examples of **correct** code for this rule:
34
35```js
36expect(something).toMatchInlineSnapshot();
37
38expect(something).toMatchInlineSnapshot(
39 `Object {
40 property: 1
41 }`,
42);
43
44expect(something).toMatchInlineSnapshot(
45 { property: expect.any(Date) },
46 `Object {
47 property: Any<Date>
48 }`,
49);
50
51expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot();
52
53expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(
54 `Error Message`,
55);
56```
57
58## When Not To Use It
59
60Don't use this rule on non-jest test files.
Note: See TracBrowser for help on using the repository browser.