bun-test-basics
Use for bun:test syntax, assertions, describe/it, test.skip/only/each, and basic patterns.
What this skill does
# Bun Test Basics
Bun ships with a fast, built-in, Jest-compatible test runner. Tests run with the Bun runtime and support TypeScript/JSX natively.
## Quick Start
```bash
# Run all tests
bun test
# Run specific file
bun test ./test/math.test.ts
# Run tests matching pattern
bun test --test-name-pattern "addition"
```
## Writing Tests
```typescript
import { test, expect, describe } from "bun:test";
test("2 + 2", () => {
expect(2 + 2).toBe(4);
});
describe("math", () => {
test("addition", () => {
expect(1 + 1).toBe(2);
});
test("subtraction", () => {
expect(5 - 3).toBe(2);
});
});
```
## Test File Patterns
Bun discovers test files matching:
- `*.test.{js|jsx|ts|tsx}`
- `*_test.{js|jsx|ts|tsx}`
- `*.spec.{js|jsx|ts|tsx}`
- `*_spec.{js|jsx|ts|tsx}`
## Test Modifiers
```typescript
// Skip a test
test.skip("not ready", () => {
// won't run
});
// Only run this test
test.only("focus on this", () => {
// other tests won't run
});
// Placeholder for future test
test.todo("implement later");
// Expected to fail
test.failing("known bug", () => {
throw new Error("This is expected");
});
```
## Parameterized Tests
```typescript
test.each([
[1, 1, 2],
[2, 2, 4],
[3, 3, 6],
])("add(%i, %i) = %i", (a, b, expected) => {
expect(a + b).toBe(expected);
});
// With objects
test.each([
{ a: 1, b: 2, expected: 3 },
{ a: 5, b: 5, expected: 10 },
])("add($a, $b) = $expected", ({ a, b, expected }) => {
expect(a + b).toBe(expected);
});
```
## Concurrent Tests
```typescript
// Run tests in parallel
test.concurrent("async test 1", async () => {
await fetch("/api/1");
});
test.concurrent("async test 2", async () => {
await fetch("/api/2");
});
// Force sequential when using --concurrent
test.serial("must run alone", () => {
// runs sequentially
});
```
## Common Matchers
```typescript
// Equality
expect(value).toBe(4); // Strict equality
expect(obj).toEqual({ a: 1 }); // Deep equality
expect(value).toStrictEqual(4); // Strict + type
// Truthiness
expect(value).toBeTruthy();
expect(value).toBeFalsy();
expect(value).toBeNull();
expect(value).toBeDefined();
expect(value).toBeUndefined();
// Numbers
expect(value).toBeGreaterThan(3);
expect(value).toBeGreaterThanOrEqual(3);
expect(value).toBeLessThan(5);
expect(value).toBeCloseTo(0.3, 5); // Floating point
// Strings
expect(str).toMatch(/pattern/);
expect(str).toContain("substring");
expect(str).toStartWith("Hello");
expect(str).toEndWith("world");
// Arrays
expect(arr).toContain(item);
expect(arr).toContainEqual({ a: 1 });
expect(arr).toHaveLength(3);
// Objects
expect(obj).toHaveProperty("key");
expect(obj).toHaveProperty("key", value);
expect(obj).toMatchObject({ a: 1 });
// Exceptions
expect(() => fn()).toThrow();
expect(() => fn()).toThrow("message");
expect(() => fn()).toThrow(CustomError);
// Async
await expect(promise).resolves.toBe(value);
await expect(promise).rejects.toThrow();
// Negation
expect(value).not.toBe(5);
```
## CLI Options
```bash
# Timeout per test (default 5000ms)
bun test --timeout 20
# Bail after N failures
bun test --bail
bun test --bail=10
# Watch mode
bun test --watch
# Random order
bun test --randomize
bun test --seed 12345
# Concurrent execution
bun test --concurrent
bun test --concurrent --max-concurrency 4
# Filter by name
bun test -t "pattern"
```
## Output Reporters
```bash
# Dots (compact)
bun test --dots
# JUnit XML (CI/CD)
bun test --reporter=junit --reporter-outfile=./results.xml
```
## Common Errors
| Error | Cause | Fix |
|-------|-------|-----|
| `Test timeout` | Test exceeds 5s | Use `--timeout` or optimize |
| `No tests found` | Wrong file pattern | Check file naming |
| `expect is not defined` | Missing import | Import from `bun:test` |
| `Assertion failed` | Test failure | Check expected vs actual |
## When to Load References
Load `references/matchers.md` when:
- Need complete matcher reference
- Custom matcher patterns
Load `references/cli-options.md` when:
- Full CLI flag reference
- Advanced execution options
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.