10LOC

#bun-test

Bunintermediate

A tiny Bun test fixture helper

import { beforeEach, afterEach, test, expect } from "bun:test";
import { file } from "bun";
import { mkdtemp, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";

Keep Bun tests small by extracting repeated setup into a fixture helper.

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.