bun:test module. All test functions (test, describe, expect, beforeAll, etc.) are also available as globals — no import required — for full Jest compatibility.
Basic usage
math.test.ts
Grouping tests
Usedescribe() to group related tests into a suite:
math.test.ts
Async tests
Tests can be async. Bun awaits the returned promise before marking the test as complete.done callback. If you declare it as a parameter, you must call it or the test will time out.
Timeouts
Pass a timeout in milliseconds as the third argument totest(). The default is 5000ms.
Test modifiers
test.skip
Skip a test without deleting it. Skipped tests are not executed.test.todo
Mark a test as a planned but unimplemented case:bun test --todo to find any todo tests that are unexpectedly passing.
test.only
Run only the tests (or suites) marked with.only. Use bun test --only to enforce this.
test.if / test.skipIf / test.todoIf
Run, skip, or mark a test as todo based on a runtime condition:describe blocks, affecting all tests within.
test.failing
Usetest.failing to mark a test you know is currently broken. The test passes when it fails, and fails when it unexpectedly passes:
test.concurrent / test.serial
Control concurrency at the individual test level. See Test Runner for details.Assertion counting
Useexpect.assertions() to verify a specific number of assertions ran — essential for async code with conditional branches:
expect.hasAssertions() to require at least one assertion:
Retries and repeats
You cannot use both
retry and repeats on the same test.Parameterized tests
test.each
Run the same test with multiple sets of data:$key syntax:
describe.each
Create a parameterized suite that runs all its tests for each case:Format specifiers
Type testing
Bun includesexpectTypeOf for type-level assertions, compatible with Vitest. These are no-ops at runtime — run bunx tsc --noEmit to validate types.
Matchers reference
Basic
Strings and arrays
Objects
Numbers
Functions and errors
Mock functions
Snapshots
Best practices
Use descriptive test names
Use descriptive test names
Use specific matchers
Use specific matchers
Test error conditions
Test error conditions