Testing
Pun has a built-in test runner that supports TypeScript and hot reloading.
Writing Tests
Create a file ending in .test.ts or .test.js.
import { test, expect, describe } from "pun:test";
describe("Math operations", () => {
test("addition works", () => {
expect(2 + 2).toBe(4);
});
test("arrays are equal", () => {
expect([1, 2, 3]).toEqual([1, 2, 3]);
});
});
Running Tests
Run all tests in the project:
pun test
Run a specific test file:
pun test src/math.test.ts
Options
--watch: Automatically rerun tests when files change.--coverage: Generate a code coverage report.
Assertion API
Pun's expect provides several matchers:
.toBe(value): Strict equality (===)..toEqual(value): Deep equality..toBeGreaterThan(value).toBeLessThan(value).toThrow(error).rejects.toThrow(error)