---
url: /docs/guide/usage/linter/rules/vitest/no-interpolation-in-snapshots.md
---

### 作用

禁止在快照中使用字符串插值。

### 为什么这不好？

插值会阻止快照被更新。相反，应当通过使用
[属性匹配器](https://jestjs.io/docs/en/snapshot-testing#property-matchers)
来用匹配器覆盖属性。

### 示例

以下是此规则的**错误**代码示例：

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

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

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

## 如何使用

## 版本

此规则于 v0.0.13 中添加。

## 参考资料
