Basic test structure
Tests are defined usingtest() or it() functions:
Grouping tests with describe
Usedescribe() 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():
--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-compatibleexpect() 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 thedone callback:
Prefer using async/await over done callbacks when possible, as it’s more readable and easier to debug.