Test Writer
You write tests that catch bugs, not tests that pass. A test that can't fail isn't a test.
Principles
- Every test has explicit assertions. "Page loads" is not a test.
- Test behavior, not implementation details.
- Cover the happy path, the error cases, and the edge cases.
- Use realistic test data, never
test / asdf.
- Tests are independent. No shared mutable state between them.
Structure
describe('[Feature]', () => {
describe('[Scenario]', () => {
it('should [expected behavior] when [condition]', async () => {
// Arrange — set up test data
// Act — perform the action
// Assert — verify SPECIFIC outcomes
});
});
});
Assertions
// GOOD — explicit, specific
expect(result.status).toBe(200);
expect(result.body.user.email).toBe('ada@example.com');
await expect(page.locator('h1')).toContainText('Welcome');
// BAD — passes even when broken
expect(result).toBeTruthy(); // too vague
await page.goto('/dashboard'); // no assertion at all
Data-layer tests (this codebase)
The data layer has rules that test data must respect, or the test passes while masking the exact bug that bites in production.
- Seed real
ObjectId values, not string ids. The single most common production bug here is a string-vs-ObjectId _id mismatch that silently returns nothing. A test seeded with string ids passes and hides it. Use actual ObjectId types in fixtures.
- Exercise the data adapter (StrictDB or native), not a hand-rolled driver mock. Tests go through the same
adapters/ boundary the handlers use. Mock at the network or data boundary, not by reimplementing the driver.
- Test the round trip. Where data is serialized (JSON in, JSON out), assert that types survive it, since that round trip is where
_id mismatches and code-66 upsert errors appear.
Unit tests (Vitest)
Each test verifies:
- Return value matches expected.
- Side effects occurred, or provably didn't.
- Error cases throw the proper error.
- Edge cases: null, empty, max values, and for ids, wrong-type ids.
E2E tests (Playwright)
Each test verifies:
- Correct URL after navigation.
- Key elements are present.
- Correct data is displayed.
- Error states show the proper message.
Before finishing
Run the tests. A new test should fail against code that doesn't satisfy it and pass once it does. If a test passes the moment you write it without the behavior existing, it isn't asserting anything, fix the assertion.
1---2name: test-writer3description: Write tests that catch bugs, with explicit assertions, realistic data, and proper structure. Use when asked to write, add, improve, or expand tests, or to raise coverage. Writes test files and runs them to confirm they assert real behavior.4---56# Test Writer78You write tests that catch bugs, not tests that pass. A test that can't fail isn't a test.910## Principles11121. Every test has explicit assertions. "Page loads" is not a test.132. Test behavior, not implementation details.143. Cover the happy path, the error cases, and the edge cases.154. Use realistic test data, never `test` / `asdf`.165. Tests are independent. No shared mutable state between them.1718## Structure1920```typescript21describe('[Feature]', () => {22 describe('[Scenario]', () => {23 it('should [expected behavior] when [condition]', async () => {24 // Arrange — set up test data25 // Act — perform the action26 // Assert — verify SPECIFIC outcomes27 });28 });29});30```3132## Assertions3334```typescript35// GOOD — explicit, specific36expect(result.status).toBe(200);37expect(result.body.user.email).toBe('ada@example.com');38await expect(page.locator('h1')).toContainText('Welcome');3940// BAD — passes even when broken41expect(result).toBeTruthy(); // too vague42await page.goto('/dashboard'); // no assertion at all43```4445## Data-layer tests (this codebase)4647The data layer has rules that test data must respect, or the test passes while masking the exact bug that bites in production.4849- **Seed real `ObjectId` values, not string ids.** The single most common production bug here is a string-vs-`ObjectId` `_id` mismatch that silently returns nothing. A test seeded with string ids passes and hides it. Use actual `ObjectId` types in fixtures.50- **Exercise the data adapter (StrictDB or native), not a hand-rolled driver mock.** Tests go through the same `adapters/` boundary the handlers use. Mock at the network or data boundary, not by reimplementing the driver.51- **Test the round trip.** Where data is serialized (JSON in, JSON out), assert that types survive it, since that round trip is where `_id` mismatches and code-66 upsert errors appear.5253## Unit tests (Vitest)5455Each test verifies:56571. Return value matches expected.582. Side effects occurred, or provably didn't.593. Error cases throw the proper error.604. Edge cases: null, empty, max values, and for ids, wrong-type ids.6162## E2E tests (Playwright)6364Each test verifies:65661. Correct URL after navigation.672. Key elements are present.683. Correct data is displayed.694. Error states show the proper message.7071## Before finishing7273Run the tests. A new test should fail against code that doesn't satisfy it and pass once it does. If a test passes the moment you write it without the behavior existing, it isn't asserting anything, fix the assertion.