快照測試使用 .toMatchSnapshot()
比對器撰寫
import { test, expect } from "bun:test";
test("snap", () => {
expect("foo").toMatchSnapshot();
});
第一次執行此測試時,expect
的引數會序列化並寫入測試檔案旁 __snapshots__
目錄中的特殊快照檔案。在後續執行時,引數會與磁碟上的快照進行比較。快照可以使用下列指令重新產生
bun test --update-snapshots