Il test runner di Bun supporta il testing di snapshot in stile Jest tramite .toMatchSnapshot().
ts
import { test, expect } from "bun:test";
test("snapshot", () => {
expect({ foo: "bar" }).toMatchSnapshot();
});La prima volta che questo test viene eseguito, Bun scriverà un file di snapshot su disco in una directory chiamata __snapshots__ che si trova accanto al file di test.
txt
test
├── __snapshots__
│ └── snap.test.ts.snap
└── snap.test.tsPer rigenerare gli snapshot, usa il flag --update-snapshots.
sh
bun test --update-snapshotstxt
test/snap.test.ts:
✓ snapshot [0.86ms]
1 pass
0 fail
snapshots: +1 added # lo snapshot è stato rigenerato
1 expect() calls
Ran 1 tests across 1 files. [102.00ms]Vedi Docs > Test Runner > Snapshots per la documentazione completa sugli snapshot con il test runner di Bun.