Files
olekhondera 5b28ea675d add SKILL
2026-02-14 07:38:50 +02:00

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

  1. Read the target file and understand:

    • What it does (component, service, utility, API handler)
    • Its dependencies and side effects
    • Edge cases and error paths
  2. Read project context:

    • Check RECOMMENDATIONS.md for testing stack decisions
    • Look at existing test files for patterns and conventions
    • Check test config (vitest.config, playwright.config)
  3. 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.tsx next to Component.tsx

    Queries (for React components):

    • getByRolegetByLabelTextgetByTextgetByTestId (last resort)
    • Use userEvent over fireEvent

    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
  4. No arbitrary waits — use waitFor, findBy, or proper async handling.

  5. Output: working test file, ready to run with vitest.