testing-patterns

Implements Jest testing patterns, factory functions, and mocking strategies for TDD workflows.

1|Updated Aug 17, 2025
One-click install
npx skills add https://github.com/ratnesh-maurya/mdconverter --skill testing-patterns-ratnesh-maurya
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/ratnesh-maurya/mdconverter/tree/main/.claude/skills/testing-patterns
Command: npx skills add https://github.com/ratnesh-maurya/mdconverter --skill testing-patterns-ratnesh-maurya

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing consistent, maintainable unit tests is hard when test data is duplicated, mocks are inconsistent, and tests verify implementation details instead of behavior. This Skill provides proven Jest patterns for factory functions, mocking, and TDD workflows. ## Core Features & Use Cases - Factory Functions: Create reusable getMockX(overrides) factories for component props and data models with sensible defaults. - Mocking Strategies: Mock modules, GraphQL hooks, and functions using jest.mock and jest.requireMock patterns. - TDD Workflow: Follow the red-green-refactor cycle with behavior-driven test structure using nested describe blocks. - Use Case: When writing tests for a React Native component, use the custom render utility with theme providers and a props factory to test loading, error, and interaction states without duplicating setup code. ## Quick Start Write Jest unit tests for my component using factory functions for props and proper mocking of its data hooks.

Frequently Asked Questions about testing-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write Jest tests with factory functions?

Create a getMockX function that returns default values and spreads an optional overrides parameter, such as getMockUser({ role: 'admin' }). This keeps test data DRY and consistent across all tests while allowing per-test customization.

How to mock GraphQL hooks in Jest tests?

Use jest.mock on the generated hooks file with a factory returning jest.fn() for the hook, then access it via jest.requireMock. Set return values per test with mockReturnValue to control data, loading, and error states.

What is the TDD red-green-refactor cycle?

TDD means writing a failing test first, implementing the minimal code to make it pass, then refactoring while tests stay green. Never write production code without a failing test driving it.

Does this testing approach work with React Native Testing Library?

Yes, the patterns use @testing-library/react-native with a custom render function that wraps components in required providers like ThemeProvider. Queries use screen.getByText, queryByText, and fireEvent for interactions.

Why should tests avoid testing mock behavior?

Asserting that a mock was called only verifies the mock, not real behavior. Instead, assert on observable outcomes like rendered text or state changes, which keeps tests resilient to implementation refactors.