> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 在 `bun test` 中更新快照

Bun 的测试运行器支持 Jest 风格的使用 `.toMatchSnapshot()` 的快照测试。

```ts snap.test.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
import { test, expect } from "bun:test";

test("快照", () => {
  expect({ foo: "bar" }).toMatchSnapshot();
});
```

***

首次运行此测试时，Bun 会将快照文件写入测试文件旁边的 `__snapshots__` 目录中。

```txt 文件树 icon="folder-tree" theme={null}
test
├── __snapshots__
│   └── snap.test.ts.snap
└── snap.test.ts
```

***

要重新生成快照，请使用 `--update-snapshots` 标志。

```sh terminal icon="terminal" theme={null}
bun test --update-snapshots
```

```txt theme={null}
test/snap.test.ts:
✓ 快照 [0.86ms]

 1 通过
 0 失败
 快照：+1 已添加 # 快照已重新生成
 1 个 expect() 调用
跨 1 个文件运行了 1 个测试。 [102.00ms]
```

***

参见 [快照](/test/snapshots)。
