module
bun:test
The 'bun:test' module is a fast, built-in test runner that aims for Jest compatibility. Tests are executed with the Bun runtime, providing significantly improved performance over traditional test runners.
Key features include TypeScript and JSX support, lifecycle hooks (beforeAll, beforeEach, afterEach, afterAll), snapshot testing, UI & DOM testing, watch mode, and script pre-loading. The API supports test assertions with expect, test grouping with describe, mocks, and more.
While Bun aims for compatibility with Jest, not everything is implemented yet. Use bun test to automatically discover and run tests matching common patterns like *.test.ts or *.spec.js.
Functions 8
- afterAll()
Runs a function, once, after all the tests.
- afterEach()
Runs a function after each test.
- beforeAll()
Runs a function, once, before all the tests.
- beforeEach()
Runs a function before each test.
- onTestFinished()
Runs a function after a test finishes, including after all afterEach hooks.
- setDefaultTimeout()
Sets the default timeout for all tests in the current file.
- setSystemTime()
Control the system time used by.
- spyOn()
Create a spy on an object property or method
Interfaces 10
- interface AsymmetricMatchers
You can extend this interface with declaration merging, in order to add type support for custom asymmetric matchers.
- interface AsymmetricMatchersBuiltin
- interface Describe
Describes a group of related tests.
- interface Expect
You can extend this interface with declaration merging, in order to add type support for custom asymmetric matchers.
- interface MatcherResult
- interface Matchers
You can extend this interface with declaration merging, in order to add type support for custom matchers.
- interface MatchersBuiltin
- interface Test
Runs a test.
- interface TesterContext
- interface TestOptions
Types 7
- type AsymmetricMatcher
Object representing an asymmetric matcher obtained by an static call to expect like
expect.anything(),expect.stringContaining("..."), etc. - type CustomMatcher
- type CustomMatchersDetected
All non-builtin matchers and asymmetric matchers that have been type-registered through declaration merging
- type EqualsFunction
- type ExpectExtendMatchers
If the types has been defined through declaration merging, enforce it.
- type Mock
- type Tester
Custom equality tester
Variables 8
- const describe
Describes a group of related tests.
- const expect
Asserts that a value matches some criteria.
- const expectTypeOf
- const mock
- const test
Runs a test.
- const vi
Vitest-compatible mocking utilities
- const xdescribe
Skips a group of related tests.
- const xtest
Skips a test.