Skip to main content
Bun’s test runner provides a Jest-compatible API for writing tests. If you’re familiar with Jest, Vitest, or other test frameworks, you’ll feel right at home.

Basic test structure

Tests are defined using test() or it() functions:

Grouping tests with describe

Use describe() to group related tests:

Async tests

Tests can be async. Bun will wait for the promise to resolve:

Test timeout

By default, tests timeout after 5 seconds. You can customize this:

Skipping tests

Skip tests with .skip() or test.skip():

Only running specific tests

Run only specific tests with .only():
You can also use the --only flag to run only tests marked with .only() across your entire test suite:

Todo tests

Mark tests as todo when you’re planning to implement them:

Concurrent tests

Run tests concurrently to speed up test execution:

Expectations

Bun provides a Jest-compatible expect() API:

Negation

Negate any matcher with .not:

Custom matchers

Extend expect with custom matchers:

Test context

You can optionally pass a test context object with the done callback:
Prefer using async/await over done callbacks when possible, as it’s more readable and easier to debug.

Parameterized tests

Run the same test with different inputs: