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