testing-patterns

Write Jest unit tests with factories, mocks, and async UI assertions.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/snuffomega/pricechart --skill testing-patterns-snuffomega
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing-patterns
Source: https://github.com/snuffomega/pricechart/tree/main/.skills/testing-patterns
Command: npx skills add https://github.com/snuffomega/pricechart --skill testing-patterns-snuffomega

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps you create clear, maintainable, and trustworthy unit tests (often using TDD) so bugs get caught early and refactors don’t break behavior.

Core Features & Use Cases

  • Test-Driven Development workflow: write failing tests first, implement minimal changes, then refactor once tests pass.
  • Factory-pattern test data and props: generate consistent mock props/data with easy overrides to keep tests DRY.
  • Practical mocking strategies: mock modules and generated hooks in a controlled way to isolate behavior.
  • Query and interaction testing patterns: assert synchronous and async UI outcomes and validate user interactions.
  • Use case: when developing a screen that loads data, you can test empty, loading, success, and error states while keeping test fixtures reusable via factories.

Quick Start

Ask the AI: "Using Jest and Testing Library, show me a TDD-style test structure for a component with loading and error states, using a prop/data factory and a module mock."

Frequently Asked Questions about testing-patterns

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

FAQPage Schema
How do I structure Jest tests for React components with loading and error states?

Structure Jest tests for loading and error states by asserting synchronous and async UI outcomes using waitFor and findBy patterns. Validate user interactions while isolating component behavior through controlled module mocks and reusable test data factories.

What's the best way to mock generated hooks and modules in Jest?

Mock generated hooks and modules in Jest using controlled mocking strategies to isolate behavior. Apply jest mocking patterns to replace module implementations, ensuring your unit tests validate component logic without triggering actual hook or module side effects.

How do I use test factories to keep Jest test fixtures DRY?

Use test factories to generate consistent mock props and data with easy overrides, keeping Jest test fixtures DRY. Factory-pattern test data provides a reusable baseline for validating empty, loading, success, and error states across multiple component tests.

How does TDD red-green-refactor discipline apply to writing unit tests?

TDD red-green-refactor discipline applies to unit tests by having you write failing tests first, implement minimal code changes to pass them, then refactor. This behavior-focused testing approach catches bugs early and prevents refactors from breaking existing functionality.

Can I use React Testing Library to validate async user interactions and UI queries?

Yes, React Testing Library validates both synchronous and async UI outcomes by asserting queries and user interactions. Apply waitFor and findBy patterns to robustly test asynchronous flows, ensuring UI elements appear and behave correctly after data loads.

Why do my Jest async tests fail when asserting UI elements that load data?

Jest async tests fail when asserting data-loaded UI elements if synchronous queries are used instead of async patterns. Apply waitFor or findBy methods to wait for asynchronous rendering to complete before asserting query outcomes and validating user interactions.