| Hook | Description |
|---|---|
beforeAll | Runs once before all tests. |
beforeEach | Runs before each test. |
afterEach | Runs after each test. |
afterAll | Runs once after all tests. |
onTestFinished | Runs after a single test finishes (after all afterEach). |
Per-Test Setup and Teardown
Perform per-test setup and teardown logic withbeforeEach and afterEach.
Per-Scope Setup and Teardown
Perform per-scope setup and teardown logic withbeforeAll and afterAll. The scope is determined by where the hook is defined.
Scoped to a Describe Block
To scope the hooks to a particular describe block:Scoped to a Test File
To scope the hooks to an entire test file:onTestFinished
Use onTestFinished to run a callback after a single test completes. It runs after all afterEach hooks.
test.serial instead.
Global Setup and Teardown
To scope the hooks to an entire multi-file test run, define the hooks in a separate file.--preload to run the setup script before any test files.
terminal
--preload every time you run tests, it can be added to your bunfig.toml:
bunfig.toml