Engineering
testing-patterns avatar

testing-patterns

Jest testing patterns, factory functions, mocking strategies, and TDD workflow. Use when writing unit tests, creating test factories, or following TDD red-green-refactor cycle.

Introduction

This skill provides a standardized framework for implementing robust, maintainable unit tests within a React Native and TypeScript environment. It is designed for software engineers who prioritize code quality and want to enforce a consistent testing culture. By adopting these patterns, developers can ensure their test suites remain DRY (Don't Repeat Yourself), readable, and tightly coupled to user-facing behavior rather than implementation details. The skill is particularly effective for teams aiming to reduce technical debt through rigorous TDD (Test-Driven Development) and clear mocking standards.

  • Implements the TDD cycle: write failing tests first, satisfy with minimal code, and refactor for maintainability.

  • Utilizes the factory pattern for test data and component props to ensure consistent, reusable, and type-safe mock objects.

  • Provides templates for custom render functions to wrap components in necessary providers (e.g., ThemeProvider) for integration tests.

  • Defines mocking strategies for complex modules, GraphQL hooks, and third-party dependencies using Jest.

  • Enforces behavioral testing by focusing on public APIs and business requirements instead of internal implementation details.

  • Outlines best practices for test structure using describe blocks, proper lifecycle management (beforeEach), and asynchronous query patterns.

  • Use this skill when initiating new feature development or during bug reproduction to define clear acceptance criteria.

  • Inputs include React components, data interfaces, and specific user stories; outputs are clean, isolated, and descriptive test files.

  • Strictly avoid common anti-patterns like testing mock behavior, missing empty states in list components, or manual, duplicated test data creation.

  • Always clear mocks between tests and ensure that each test focuses on a single behavioral outcome.

  • Leverages testing-library/react-native for queries like getByText, findByText, and waitFor to simulate user interactions effectively.

  • Integrates seamlessly with other engineering skills like systematic-debugging for root cause analysis and react-ui-patterns for verifying UI component states.

Repository Stats

Stars
5,850
Forks
543
Open Issues
13
Language
JavaScript
Default Branch
main
Sync Status
Idle
Last Synced
Apr 29, 2026, 08:34 AM
View on GitHub