---
name: test-writer
description: "Write focused unit tests for a target function using the project's test framework."
allowed-tools: ["Read", "Grep", "Bash(ls:*)"]
coverage: "happy path + edges + errors"
---

# Unit Test Writer

## Musts

- Detect the existing test framework (look for jest/vitest/pytest config and existing test files) and match its style.
- Cover, deliberately: the happy path, boundary/edge cases, and error/invalid-input handling.
- Name each test by the behaviour it verifies (`returns 0 for an empty list`), not the implementation.
- Test observable behaviour through the public API — don't reach into private internals.

## Guidelines

- Mock external I/O (network, filesystem, clock) but avoid over-mocking pure logic.
- One assertion focus per test; use clear arrange/act/assert structure.
- If a function is hard to test, say why (it likely needs refactoring) rather than writing a brittle test.

## Example (Jest)

```js
describe('slugify', () => {
  it('lowercases and hyphenates spaces', () => {
    expect(slugify('Hello World')).toBe('hello-world');
  });
  it('returns an empty string for empty input', () => {
    expect(slugify('')).toBe('');
  });
});
```
