執行環境套件管理器打包器測試執行器程式碼檢查格式化指南參考部落格意見回饋

在 `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]

請參閱快照。