# testing-patterns

A Claude skill that hands the agent Jest testing patterns: data factories, module mocks and the red-green-refactor loop.

- skill · `type=skill` · Claude Code · 365 installs
- Author: davila7
- License: not stated · policy=link-only · description only; the file stays with the author
- Source: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/skills/development/testing-patterns
- Updated: 2026-10-24
- HTML: https://affpapa.org/en/nevibecode/skills/testing-patterns

## What it does

The skill sets rules for how the agent writes tests: a failing test comes first, then the smallest implementation that passes, then refactoring once it is green. It ships templates for Jest and React Native Testing Library — a custom render that wraps components in providers, prop and data factories like `getMockUser(overrides)`, and module or GraphQL hook mocks through `jest.mock` and `jest.requireMock`.

Test structure gets its own section: `describe` groups, `beforeEach` with `jest.clearAllMocks()`, queries via `getByText`, `queryByText` and `waitFor`, interactions via `fireEvent`. There is also a list of anti-patterns, including asserting on a mock call instead of real behaviour and duplicating test data without factories.

The examples assume Jest, `@testing-library/react-native` and TypeScript, so on a different runner you will rewrite them. Running tests is covered with `npm test`, `npm run test:coverage` and `npm test ComponentName.test.tsx`.

## Install

### Claude Code (native platform)

1. **claude-code-templates**
```bash
npx claude-code-templates@latest --skill development/testing-patterns
```

2. **Skills CLI (Vercel)**
```bash
npx skills add davila7/claude-code-templates --skill testing-patterns -a claude-code
```

3. **Manually: put the files in place**
- File: `~/.claude/skills/testing-patterns/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/testing-patterns/

### Codex

**Manually: put the files in place**
- File: `.agents/skills/testing-patterns/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

**Manually: put the files in place**
- File: `.cursor/skills/testing-patterns/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install davila7/claude-code-templates testing-patterns
```

2. **Manually: put the files in place**
- File: `.github/skills/testing-patterns/SKILL.md`

### Gemini CLI

**Platform CLI**
```bash
gemini skills install https://github.com/davila7/claude-code-templates --path cli-tool/components/skills/development/testing-patterns
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/testing-patterns/SKILL.md` — The legacy .windsurf/skills/ path still works

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/davila7/claude-code-templates/tree/HEAD/cli-tool/components/skills/development/testing-patterns

## When to use it
- write a failing test before the implementation
- build a mock data factory with field overrides
- mock a module or a GraphQL hook inside a test
- wrap a component in providers when rendering
- split tests into groups and clear mocks between them

## Example prompts
- write a test for LoginForm following testing-patterns
- create a getMockUser factory with the admin role
- mock useGetItemsQuery and assert the empty list state

## Similar
- [python-testing-patterns](https://affpapa.org/en/nevibecode/skills/python-testing-patterns.md) — skill · 36943 installs
- [testing-best-practices](https://affpapa.org/en/nevibecode/skills/testing-best-practices.md) — skill · 899 installs
- [testing-anti-patterns](https://affpapa.org/en/nevibecode/skills/testing-anti-patterns.md) — skill · 368 installs
- [appbuilder-testing](https://affpapa.org/en/nevibecode/skills/appbuilder-testing.md) — skill · 714 installs
- [typescript-unit-testing](https://affpapa.org/en/nevibecode/skills/typescript-unit-testing.md) — skill · 496 installs
- [python-testing](https://affpapa.org/en/nevibecode/skills/python-testing.md) — skill · 4900 installs

From the same set: [davila7/claude-code-templates](https://affpapa.org/en/nevibecode/by/davila7/claude-code-templates.md) — 205 cards

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
