10LOC

#snapshot-testing

Bunintermediate

Snapshot testing with bun:test in 10 lines

import { test, expect } from "bun:test";

const formatInvoice = (id: number, cents: number) => ({
  id,
  total: `$${(cents / 100).toFixed(2)}`,

toMatchSnapshot() saves a value's serialized shape on first run and diffs it on every run after, catching output changes you didn't write assertions for.