jest/no-interpolation-in-snapshots 樣式
作用
防止在快照中使用字串插值。
為什麼這不好?
插值會阻止快照更新。相反地,應該使用 屬性匹配器 來覆寫屬性。
範例
javascript
expect(something).toMatchInlineSnapshot(
`Object {
property: ${interpolated}
}`,
);
expect(something).toMatchInlineSnapshot(
{ other: expect.any(Number) },
`Object {
other: Any<Number>,
property: ${interpolated}
}`,
);
expect(errorThrowingFunction).toThrowErrorMatchingInlineSnapshot(`${interpolated}`);