React 19 Test Migration Patterns

React 19 Test Migration Patterns

Gives before/after patterns for migrating React test files to React 19, covering act imports, removed Simulate helpers and StrictMode call counts.

Skill files1 file
SKILL.md102 lines
1
---
2
name: react19-test-patterns
3
description: 'Provides before/after patterns for migrating test files to React 19 compatibility, including act() imports, Simulate removal, and StrictMode call count changes.'
4
---
5
6
# React 19 Test Migration Patterns
7
8
Reference for all test file migrations required by React 19.
9
10
## Priority Order
11
12
Fix test files in this order; each layer depends on the previous:
13
14
1. **`act` import** fix first, it unblocks everything else
15
2. **`Simulate` → `fireEvent`** fix immediately after act
16
3. **Full react-dom/test-utils cleanup** remove remaining imports
17
4. **StrictMode call counts** measure actual, don't guess
18
5. **Async act wrapping** for remaining "not wrapped in act" warnings
19
6. **Custom render helper** verify once per codebase, not per test
20
21
---
22
23
## 1. act() Import Fix
24
25
```jsx
26
// Before REMOVED in React 19:
27
import { act } from 'react-dom/test-utils';
28
29
// After:
30
import { act } from 'react';
31
```
32
33
If mixed with other test-utils imports:
34
```jsx
35
// Before:
36
import { act, Simulate, renderIntoDocument } from 'react-dom/test-utils';
37
38
// After split the imports:
39
import { act } from 'react';
40
import { fireEvent, render } from '@testing-library/react'; // replaces Simulate + renderIntoDocument
41
```
42
43
---
44
45
## 2. Simulate → fireEvent
46
47
```jsx
48
// Before Simulate REMOVED in React 19:
49
import { Simulate } from 'react-dom/test-utils';
50
Simulate.click(element);
51
Simulate.change(input, { target: { value: 'hello' } });
52
Simulate.submit(form);
53
Simulate.keyDown(element, { key: 'Enter', keyCode: 13 });
54
55
// After:
56
import { fireEvent } from '@testing-library/react';
57
fireEvent.click(element);
58
fireEvent.change(input, { target: { value: 'hello' } });
59
fireEvent.submit(form);
60
fireEvent.keyDown(element, { key: 'Enter', keyCode: 13 });
61
```
62
63
---
64
65
## 3. react-dom/test-utils Full API Map
66
67
| Old (react-dom/test-utils) | New location |
68
|---|---|
69
| `act` | `import { act } from 'react'` |
70
| `Simulate` | `fireEvent` from `@testing-library/react` |
71
| `renderIntoDocument` | `render` from `@testing-library/react` |
72
| `findRenderedDOMComponentWithTag` | `getByRole`, `getByTestId` from RTL |
73
| `findRenderedDOMComponentWithClass` | `getByRole` or `container.querySelector` |
74
| `scryRenderedDOMComponentsWithTag` | `getAllByRole` from RTL |
75
| `isElement`, `isCompositeComponent` | Remove not needed with RTL |
76
| `isDOMComponent` | Remove |
77
78
---
79
80
## 4. StrictMode Call Count Fixes
81
82
React 19 StrictMode no longer double-invokes `useEffect` in development. Spy assertions counting effect calls must be updated.
83
84
**Strategy always measure, never guess:**
85
```bash
86
# Run the failing test, read the actual count from the error:
87
npm test -- --watchAll=false --testPathPattern="[filename]" --forceExit 2>&1 | grep -E "Expected|Received"
88
```
89
90
```jsx
91
// Before (React 18 StrictMode effects ran twice):
92
expect(mockFn).toHaveBeenCalledTimes(2); // 1 call × 2 (strict double-invoke)
93
94
// After (React 19 StrictMode effects run once):
95
expect(mockFn).toHaveBeenCalledTimes(1);
96
```
97
98
```jsx
99
// Render-phase calls (component body) still double-invoked in React 19 StrictMode:
100
expect(renderSpy).toHaveBeenCalledTimes(2); // stays at 2 for render body calls
101
```
102

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…