Skip to main content
Bun has a built-in test runner with a Jest-like expect API.
To use it, run bun test from your project directory. The test runner recursively searches for files matching the following patterns and runs the tests they contain.
File Tree

Here’s the output of a typical run: three test files (test.test.js, test2.test.js, and test3.test.js), each containing two tests (add and multiply).
terminal

To only run certain test files, pass a positional argument to bun test. The runner only executes files with that argument in their path.
terminal

Every test has a name: the first argument to the test function. Tests can also be grouped into suites with describe.

To filter tests by name, use the -t/--test-name-pattern flag. -t add only runs tests with “add” in the name. The pattern matches test names defined with test and suite names defined with describe.
terminal

See bun test.