运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

在 `bun test` 中更新快照

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

snap.test.ts
import { test, expect } from "bun:test";

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

首次运行此测试时,Bun 会将快照文件写入与测试文件同级的 __snapshots__ 目录中。

文件树
test
├── __snapshots__
│   └── snap.test.ts.snap
└── snap.test.ts

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

terminal
bun test --update-snapshots
Text
test/snap.test.ts:
✓ snapshot [0.86ms]

 1 pass
 0 fail
 snapshots: +1 added # 快照已重新生成
 1 expect() calls
Ran 1 test across 1 file. [102.00ms]

请参阅快照。