Generate Tests Skill
Generate unit tests for a specified module, following the project's existing test conventions.
Conventions
- Test framework:
bun:test(import { test, expect, describe, beforeEach, mock } from "bun:test") - File location: Tests live in
packages/<pkg>/test/mirroring the src structure - Naming:
<module-name>.test.ts - Style: Flat
test()calls or shallowdescribe()blocks. No deep nesting.
Workflow
- Read the target module — Understand exports, types, and dependencies
- Find existing tests in the same package for pattern reference
- Generate tests covering:
- Happy path for each exported function/class
- Edge cases (empty input, null, boundary values)
- Error paths (invalid input, thrown errors)
- Use mocks sparingly — Only mock external dependencies (network, filesystem, other packages). Never mock the module under test.
- Run the tests — Execute
bun test <test-file>to verify they pass
Test structure template
import { test, expect, describe } from "bun:test";
import { functionUnderTest } from "../src/module";
describe("functionUnderTest", () => {
test("returns expected result for normal input", () => {
expect(functionUnderTest("input")).toBe("expected");
});
test("handles edge case", () => {
expect(functionUnderTest("")).toBe(null);
});
test("throws on invalid input", () => {
expect(() => functionUnderTest(null as any)).toThrow();
});
});
Rules
- No snapshot tests unless the user explicitly asks for them
- No test IDs or UUIDs — Use deterministic values
- Keep tests focused — One assertion concept per test
- Descriptive test names — Name should describe the behavior, not the implementation