Skip to content

shinpr/claude-code-workflows / dev-skills/skills/testing-principles

testing-principles

Verified

Language-agnostic testing principles for choosing which tests a change needs, test quality, and proof ownership, including frontend and browser E2E tests. Use when writing tests, deciding test scope, or reviewing test quality.

FileKindSize
SKILL.mdskill md5.7 KB
references/e2e.mdmarkdown3.0 KB
references/frontend.mdmarkdown2.5 KB

references/frontend.md

View on GitHub
# Frontend Test Implementation (React/TypeScript)

## Project Toolchain Resolution

Before writing a test, inspect package scripts, runner configuration, setup files, neighboring tests, DOM/browser environment, and network handlers. Preserve the repository's runner, imports, mock API, setup lifecycle, file naming, and test location.

- Use React Testing Library when it is the project's component-test renderer; prefer `userEvent` for user interactions.
- Use the repository's network mocking layer for API behavior. When MSW is configured, extend its handlers instead of adding runner-level fetch mocks.
- Use the configured runner's imports, module-mocking API, fake timers, and reset conventions.
- When multiple approaches coexist, choose from the behavior under test and the setup the repository maintains for it rather than from proximity alone. If none is representative and adding or replacing tooling is outside the approved work, report the missing test-environment decision.

## Test Scope

- In UI code, logic that needs its own unit tests usually lives in shared components, hooks, and utilities with a wide blast radius. Screen behavior is owned by the narrowest test that renders the real composition.
- Configuration that changes runtime or build behavior requires executable validation.

## Test Data

- Keep test data minimal and free of real sensitive values.

## Failure Classification

| Evidence | Action |
|---|---|
| Expected value or test setup contradicts the accepted contract | Fix the test |
| Implementation violates the accepted behavior or boundary | Fix the implementation |
| Both interpretations remain compatible with available requirements | Return the unresolved behavior decision |

## Helper Decision

Keep setup local until 3+ uses or a named readability/contract benefit justifies a helper. Preserve separate helpers when the scenarios have different ownership or are likely to evolve independently.

## Repository Conventions

- Preserve the repository's test location and naming. For an approved new co-located React convention, use `{ComponentName}.test.tsx`; for integration tests, use `{FeatureName}.integration.test.tsx`.
- Test rendered output, user interactions, accessibility, and observable error states rather than component internals.

## Assertion Rules

- Use mock-call assertions only when the call contract itself is the observable boundary.
- For asynchronous UI, use the repository's established async query/wait pattern and assert the resulting user-visible state.
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 319kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 319kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 319kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 196kUpdated Claude CodeCodexVerifiedInstall