Generated banner for React19 Test Patterns
Generated logo for React19 Test Patterns

React19 Test Patterns

GitHubOfficialFirst committed by SaravananRajaramanDistributed by GitHub

  • Skill
  • Guidelines
  • Software development
  • MIT
  • No issues found

From the author

Provides before/after patterns for migrating test files to React 19 compatibility, including act() imports, Simulate removal, and StrictMode call count changes.
— the description by SaravananRajaraman

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured set of patterns and migration strategies for updating test files to meet React 19 requirements. It covers the removal of deprecated react-dom/test-utils APIs, the transition to React Testing Library alternatives, and adjustments for StrictMode behavior changes regarding effect call counts.

What it does

  • Provides before/after code examples for updating act() imports.
  • Maps deprecated react-dom/test-utils functions to modern React Testing Library equivalents.
  • Outlines a prioritized migration sequence for test file updates.
  • Explains how to adjust test assertions for StrictMode effect invocation changes.
  • Offers a strategy for identifying and fixing failing tests caused by React 19 updates.

When to use it

  • When upgrading an existing React codebase to version 19.
  • When encountering test failures related to removed react-dom/test-utils imports.
  • When refactoring tests to replace Simulate with fireEvent.
  • When debugging assertion errors in tests that previously relied on StrictMode double-invocation behavior.

Advantages

  • Provides a clear, prioritized roadmap for migration.
  • Reduces guesswork when updating test assertions for StrictMode.
  • Standardizes the transition from legacy test utilities to modern testing practices.

Usage examples

“How do I update my test file imports for React 19?”
The agent will provide the pattern to change imports from 'react-dom/test-utils' to 'react' for act() and suggest replacing other utilities with '@testing-library/react' equivalents.
“My tests are failing because Simulate is gone in React 19, what should I do?”
The agent will demonstrate how to replace Simulate calls with the corresponding fireEvent methods from React Testing Library.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/github/react19-test-patterns/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip react19-test-patterns.zip -d .agents/skills

Documentation by SaravananRajaraman

React 19 Test Migration Patterns

Reference for all test file migrations required by React 19.

Priority Order

Fix test files in this order; each layer depends on the previous:

  1. act import fix first, it unblocks everything else

  2. Simulate → fireEvent fix immediately after act

  3. Full react-dom/test-utils cleanup remove remaining imports

  4. StrictMode call counts measure actual, don't guess

  5. Async act wrapping for remaining "not wrapped in act" warnings

  6. Custom render helper verify once per codebase, not per test


1. act() Import Fix

// Before  REMOVED in React 19:
import { act } from 'react-dom/test-utils';

// After:
import { act } from 'react';

If mixed with other test-utils imports:

// Before:
import { act, Simulate, renderIntoDocument } from 'react-dom/test-utils';

// After  split the imports:
import { act } from 'react';
import { fireEvent, render } from '@testing-library/react'; // replaces Simulate + renderIntoDocument

2. Simulate → fireEvent

// Before  Simulate REMOVED in React 19:
import { Simulate } from 'react-dom/test-utils';
Simulate.click(element);
Simulate.change(input, { target: { value: 'hello' } });
Simulate.submit(form);
Simulate.keyDown(element, { key: 'Enter', keyCode: 13 });

// After:
import { fireEvent } from '@testing-library/react';
fireEvent.click(element);
fireEvent.change(input, { target: { value: 'hello' } });
fireEvent.submit(form);
fireEvent.keyDown(element, { key: 'Enter', keyCode: 13 });

3. react-dom/test-utils Full API Map

Old (react-dom/test-utils)New location
actimport { act } from 'react'
SimulatefireEvent from @testing-library/react
renderIntoDocumentrender from @testing-library/react
findRenderedDOMComponentWithTaggetByRole, getByTestId from RTL
findRenderedDOMComponentWithClassgetByRole or container.querySelector
scryRenderedDOMComponentsWithTaggetAllByRole from RTL
isElement, isCompositeComponentRemove not needed with RTL
isDOMComponentRemove

4. StrictMode Call Count Fixes

React 19 StrictMode no longer double-invokes useEffect in development. Spy assertions counting effect calls must be updated.

Strategy always measure, never guess:

# Run the failing test, read the actual count from the error:
npm test -- --watchAll=false --testPathPattern="[filename]" --forceExit 2>&1 | grep -E "Expected|Received"
// Before (React 18 StrictMode  effects ran twice):
expect(mockFn).toHaveBeenCalledTimes(2);  // 1 call × 2 (strict double-invoke)

// After (React 19 StrictMode  effects run once):
expect(mockFn).toHaveBeenCalledTimes(1);
// Render-phase calls (component body)  still double-invoked in React 19 StrictMode:
expect(renderSpy).toHaveBeenCalledTimes(2);  // stays at 2 for render body calls

Files

Requirements and compatibility

Written for: GitHub Copilot

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

First committed by
GitHub avatar of SaravananRajaramanSaravananRajaraman
Publisher
GitHub (Official)
Distributed by
GitHub
Source
github/awesome-copilot · skills/react19-test-patterns · commit 797337f
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced
Contributors
SaravananRajaraman, stbenjam

AutoGineer is not affiliated with or endorsed by SaravananRajaraman or GitHub.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download react19-test-patterns.zip