1.7 KiB
1.7 KiB
name, description, disable-model-invocation, argument-hint, context, agent
| name | description | disable-model-invocation | argument-hint | context | agent |
|---|---|---|---|---|---|
| write-tests | Write tests for a specific file — unit and integration tests with Vitest, Testing Library, accessible queries, and AAA pattern. | true | [file-path] | fork | test-engineer |
Write Tests
Write comprehensive tests for $ARGUMENTS.
Steps
-
Read the target file and understand:
- What it does (component, service, utility, API handler)
- Its dependencies and side effects
- Edge cases and error paths
-
Read project context:
- Check
RECOMMENDATIONS.mdfor testing stack decisions - Look at existing test files for patterns and conventions
- Check test config (vitest.config, playwright.config)
- Check
-
Write tests following these rules:
Structure:
- AAA pattern (Arrange → Act → Assert)
- Behavior-focused names:
it('displays error when API fails') - Group by concern:
describe('when user is logged in', ...) - Co-locate with source file:
Component.test.tsxnext toComponent.tsx
Queries (for React components):
getByRole→getByLabelText→getByText→getByTestId(last resort)- Use
userEventoverfireEvent
Mocking:
- MSW for HTTP APIs
vi.mock()only for third-party services- Real implementations for internal logic
- Deterministic test data via factories
Coverage:
- Happy path
- Error states
- Empty/loading states
- Edge cases (null, undefined, empty arrays, boundary values)
- Accessibility: keyboard interaction, ARIA states
-
No arbitrary waits — use
waitFor,findBy, or proper async handling. -
Output: working test file, ready to run with
vitest.