expect
API.
To use it, run the
bun test
command from your project directory. The test runner will recursively search for all files in the directory that match the following patterns and execute the tests they contain.
File Tree
Here’s what the output of a typical test run looks like. In this case, there are three tests files (
test.test.js
, test2.test.js
, and test3.test.js
) containing two tests each (add
and multiply
).
terminal
To only run certain test files, pass a positional argument to
bun test
. The runner will only execute files that contain that argument in their path.
terminal
All tests have a name, defined using the first parameter to the
test
function. Tests can also be grouped into suites with describe
.
To filter which tests are executed by name, use the
-t
/--test-name-pattern
flag.
Adding -t add
will only run tests with “add” in the name. This works with test names defined with test
or test suite names defined with describe
.
terminal
See Docs > Test Runner for complete documentation on the test runner.