testing

Standardize Jest and Testing Library tests with waitFor, renderComponent, faker, and MSW.

8.7k|482|Updated Jul 30, 2021
One-click install
npx skills add https://github.com/redis/RedisInsight --skill testing-redis
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: testing
Source: https://github.com/redis/RedisInsight/tree/main/.ai/skills/testing
Command: npx skills add https://github.com/redis/RedisInsight --skill testing-redis

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It eliminates flaky, inconsistent tests by standardizing how RedisInsight teams write Jest and Testing Library tests for components and backend services, ensuring deterministic async behavior and maintainable setup.

Core Features & Use Cases

  • Deterministic async testing: Prefer waitFor/findBy* and waitForElementToBeRemoved instead of fixed timeouts.
  • Consistent test setup with renderComponent: Centralize providers/router/theme setup and use shared default props across component tests.
  • High-quality test data: Use @faker-js/faker (and Fishery for backend factories) to generate realistic, varied inputs instead of hardcoded values.
  • Mocking patterns with MSW: Mock API calls with Mock Service Worker for realistic request/response behavior.
  • Scope: Use these standards when creating or editing any *.spec.ts / *.spec.tsx, slice tests, service/controller tests, and critical end-to-end flows (including Playwright).

Quick Start

When adding or updating a test file, write it using the AAA pattern and replace any fixed waits with waitFor so assertions only run after the expected UI or async state is reached.

Frequently Asked Questions about testing

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

FAQPage Schema
How do I fix flaky Jest tests with inconsistent async behavior?

Fix flaky Jest tests by replacing fixed timeouts with `waitFor`, `findBy*`, or `waitForElementToBeRemoved` to ensure assertions only execute after expected UI or asynchronous state transitions complete.

What is the best way to mock API calls in Jest and Testing Library tests?

Mock API calls in Jest using Mock Service Worker (MSW) to intercept network requests and simulate realistic request and response behavior, ensuring deterministic test execution without hitting real backend endpoints.

How do I generate realistic test data for Jest unit and integration tests?

Generate realistic test data in Jest by using `@faker-js/faker` for frontend tests and Fishery factories for backend services, replacing hardcoded values with varied, randomized inputs to improve test coverage.

How do I standardize component rendering setup in Testing Library to avoid provider duplication?

Standardize Testing Library component rendering by centralizing providers, router, and theme setup into a shared `renderComponent` helper, applying consistent default props across all component and slice tests.

Can I apply these Jest testing standards to Playwright end-to-end flows?

Yes, these deterministic testing standards apply to critical end-to-end flows, including Playwright tests, when referencing Jest, Testing Library, faker, or established test patterns for services and controllers.

Why should I use waitFor instead of fixed timeouts in Testing Library tests?

Use `waitFor` instead of fixed timeouts because it dynamically polls for UI state changes, eliminating false failures caused by arbitrary delay limits and ensuring assertions run only when elements are ready.