Guidelines for writing and running unit tests using Bun's built-in test runner. Use when the user asks to write tests, add coverage, or fix failing tests.
bun test).test/ directory or alongside source files (e.g., src/foo.test.ts) depending on project structure.*.test.ts or *.spec.ts.bun:testimport { describe, it, expect, beforeEach, afterEach } from 'bun:test';
describe blocks to group tests by function or module.it or test for individual test cases.mock from bun:test for function mocking.
import { mock } from 'bun:test';
const myMock = mock(() => 'value');
afterEach if necessary.bun testbun test path/to/file.test.tsbun test --watchit('should return 404 when user not found')).