Bun Lifecycle Hooks
Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests
Install
npx skills add jarle/bun-skills --skill Bun Lifecycle hooksgit clone --depth 1 https://github.com/jarle/bun-skills.git /tmp/bun-skills
mkdir -p ~/.claude/skills
cp -r /tmp/bun-skills/skills/bun-test-lifecycle ~/.claude/skills/Bun-Lifecycle-hooksPersonal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.
From the SKILL.md
# Lifecycle hooks
> Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests
The test runner supports the following lifecycle hooks. This is useful for loading test fixtures, mocking data, and configuring the test environment.
| 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 with `beforeEach` and `afterEach`.
```ts title="test.ts" icon="https://mintcdn.com/bun-1dd33a4e/nIz6GtMH5K-dfXeV/icons/typescript.svg?fit=max&auto=format&n=nIz6GtMH5K-dfXeV&q=85&s=5d73d76daf7eb7b158469d8c30d349b0" theme={"theme":{"light":"github-light","dark":"dracula"}}
import { beforeEach, afterEach, test } from "bun:test";
beforeEach(() => {
console.log("running test.");
});
afterEach(() => {
console.log("done with test.");
});
// tests...
test("example test", () => {
// This test will have beforeEach run before it
// and afterEach run after it
});
```Details
- Skill name
Bun Lifecycle hooks- Repository
- jarle/bun-skills
- Path
skills/bun-test-lifecycle/SKILL.md- License
- MIT
- Repo updated
- 24 February 2026
FAQ
What does the Bun Lifecycle Hooks skill do?
Learn how to use beforeAll, beforeEach, afterEach, and afterAll lifecycle hooks in Bun tests
How do I install the Bun Lifecycle Hooks skill?
skills CLI (Claude Code, Cursor, Codex and more): npx skills add jarle/bun-skills --skill Bun Lifecycle hooks. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.
Is Bun Lifecycle Hooks popular?
It lives in jarle/bun-skills, which has 9 GitHub stars and 1 forks.
Related skills
Bun Archive
9jarle/bun-skills
Create and extract tar archives with Bun's fast native implementation
Bun Auto Install
9jarle/bun-skills
Bun's automatic package installation feature for standalone script execution
Bun Bun Add
9jarle/bun-skills
Add packages to your project with Bun's fast package manager
Bun Mocks
9jarle/bun-skills
Learn how to create and use mock functions, spies, and module mocks in Bun tests
Bun Import, Require, and Test Svelte Components with Bun Test
9jarle/bun-skills
import, require, and test Svelte components with bun test
Bun Re Run Tests Multiple Times with the Bun Test Runner
9jarle/bun-skills
Re-run tests multiple times with the Bun test runner
Browse the most popular Claude skills, all testing & qa skills, or write your own with the skills generator.