bun-test-lifecycle

Featured

Use for test lifecycle hooks: beforeAll, afterAll, beforeEach, afterEach, fixtures, preload.

Testing & QA 221 stars 31 forks Updated today MIT

Install

View on GitHub

Quality Score: 91/100

Stars 20%
78
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
80
License 10%
100
Description 5%
100

Skill Content

# Bun Test Lifecycle Bun supports Jest-compatible lifecycle hooks for test setup and teardown. ## Lifecycle Hooks ```typescript import { test, expect, beforeAll, afterAll, beforeEach, afterEach } from "bun:test"; let db: Database; let testData: any; // Runs once before all tests in file beforeAll(async () => { db = await Database.connect(); }); // Runs once after all tests in file afterAll(async () => { await db.close(); }); // Runs before each test beforeEach(() => { testData = { id: 1, name: "test" }; }); // Runs after each test afterEach(() => { testData = null; }); test("example", () => { expect(testData.name).toBe("test"); }); ``` ## Hook Execution Order ``` beforeAll ├── beforeEach │ └── test 1 │ └── afterEach ├── beforeEach │ └── test 2 │ └── afterEach afterAll ``` ## Nested Describe Hooks ```typescript import { describe, test, beforeAll, beforeEach, afterEach, afterAll } from "bun:test"; describe("outer", () => { beforeAll(() => console.log("1. outer beforeAll")); afterAll(() => console.log("6. outer afterAll")); beforeEach(() => console.log("2. outer beforeEach")); afterEach(() => console.log("5. outer afterEach")); describe("inner", () => { beforeEach(() => console.log("3. inner beforeEach")); afterEach(() => console.log("4. inner afterEach")); test("test", () => { console.log("test runs here"); }); }); }); // Output: // 1. outer beforeAll // 2. outer beforeEach // 3. inner beforeEach /...

Details

Author
secondsky
Repository
secondsky/claude-skills
Created
10 months ago
Last Updated
today
Language
TypeScript
License
MIT

Integrates with

Similar Skills

Semantically similar based on skill content — not just same category