testing-patterns — Claude Code skill: Jest patterns and TDD
A Claude skill that hands the agent Jest testing patterns: data factories, module mocks and the red-green-refactor loop.
npx claude-code-templates@latest --skill development/testing-patternsWhat testing-patterns 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.
What it helps with
- 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 for the agent
- write a test for LoginForm following testing-patterns
- create a getMockUser factory with the admin role
- mock useGetItemsQuery and assert the empty list state
How to install testing-patterns
1claude-code-templates
npx claude-code-templates@latest --skill development/testing-patterns2Skills CLI (Vercel)
npx skills add davila7/claude-code-templates --skill testing-patterns -a claude-code3Manually: put the files in place
~/.claude/skills/testing-patterns/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/testing-patterns/
Manually: put the files in place
.agents/skills/testing-patterns/SKILL.mdFor all projects use ~/.agents/skills/
Manually: put the files in place
.cursor/skills/testing-patterns/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install davila7/claude-code-templates testing-patterns2Manually: put the files in place
.github/skills/testing-patterns/SKILL.mdPlatform CLI
gemini skills install https://github.com/davila7/claude-code-templates --path cli-tool/components/skills/development/testing-patternsManually: put the files in place
.devin/skills/testing-patterns/SKILL.mdThe legacy .windsurf/skills/ path still works
Claude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about testing-patterns
How do I install testing-patterns in Claude?
Use the templates CLI: npx claude-code-templates@latest --skill development/testing-patterns. Alternatively run npx skills add davila7/claude-code-templates --skill testing-patterns -a claude-code. The skill file lands at ~/.claude/skills/testing-patterns/SKILL.md.
What does testing-patterns do?
It gives the agent ready-made testing patterns: prop and data factories, module and hook mocks, a describe layout with mock cleanup. It also spells out the TDD cycle and common anti-patterns.
What stack do the examples use?
Jest, @testing-library/react-native and TypeScript. With another runner or testing library you adapt the templates yourself.