# Build Reliable React Tests

React test suites often become flaky when async state, providers, and mocks are handled inconsistently. This skill gives Claude, Codex, and Claude Code practical patterns for focused React tests.

## Install

```bash
npx skillstore add cjharmath/react-testing
```

## Metadata

- Status: approved
- Slug: cjharmath-react-testing
- Skillstore revision: r1
- Version status: missing
- Tree hash: 7afef5ed609b37684ea19d7f9b44f65261f04e591475fa6f930d66aacfd5274a
- Author: CJHarmath
- GitHub username: CJHarmath
- License: MIT
- Repository: https://github.com/CJHarmath/claude-agents-skills/tree/main/skills/react-testing
- Ref: dd4a3ef9f20ddf38830950b4bb713df96b431fd6
- Supported tools: Claude, Codex, Claude Code
- Audit status: complete
- Agent install advisory: allowed
- Manual install advisory: allowed
- Artifact signature: available
- Audit attestation: unavailable
- Human verification: not\_verified
- Risk factors: external\_commands
- Quality score: 77
- Quality tier: bronze
- Public page: https://skillstore.pages.dev/skills/cjharmath-react-testing
- Manifest: https://skillstore.pages.dev/api/skills/cjharmath-react-testing/manifest

## Capabilities

- Shows how to reset Zustand store state between tests.
- Provides async testing patterns with act, waitFor, and findBy queries.
- Demonstrates component, hook, router, form, and provider test structures.
- Explains how to mock fetch calls and imported API modules.
- Lists common Jest and React Testing Library failure modes with fixes.

## Use Cases

- Add component test coverage: Create tests that verify rendering, loading states, user actions, and accessible output.
- Stabilize stateful test suites: Reset Zustand stores and React Query clients so tests stay isolated and repeatable.
- Debug async UI failures: Resolve act warnings, timing issues, missing queries, and mock mismatches in React tests.

## Prompt Templates

### Create a component test

```
Write React Testing Library tests for this component. Cover rendering, user actions, loading state, and accessible queries.
```

### Test async state

```
Create tests for this async React state flow. Include act or waitFor usage, store reset, and clear assertions after each async step.
```

### Mock providers and APIs

```
Design tests for this component with React Query, routing, context providers, and mocked API modules. Keep provider setup reusable.
```

### Diagnose a failing suite

```
Review this failing React test output and test file. Identify likely causes, explain the fix, and suggest stronger assertions.
```

## Limitations

- Focuses on React web applications, not React Native.
- Does not configure a full Jest build setup from scratch.
- Does not cover browser automation tools such as Playwright or Cypress.
- Examples are templates and need adaptation to each project.

## Best Practices

- Prefer accessible queries that match how users interact with the page.
- Reset stores, mocks, and query clients before each test.
- Wait for async UI changes before asserting final state.

## Anti Patterns

- Do not share mutable store state across test cases.
- Do not use snapshots for dynamic or frequently changing content.
- Do not ignore act warnings without checking async state updates.

## Security Audit

- Audited at: 2026-07-06T05:17:36.775\+00:00
- Summary: All static external command findings are false positives caused by Markdown code fences or inline backticks in documentation examples. The sensitive-data and reconnaissance findings are also false positives from normal test assertions. No evidence of prompt injection, data exfiltration, or malicious intent was found.

## Stats

- Views: 229
- Downloads: 12
- Favorites: 0
- Popularity score: 0
