react19-test-patterns
하는 일
이 가이드는 새 React 버전(React 19)과 작동하도록 코드 테스트를 업데이트하도록 돕습니다. 작동을 멈추거나 바뀐 테스트 코드의 특정 부분을 고치는 방법을 보여 줍니다.
사용하는 경우
- ✓프로젝트를 React 19로 업데이트할 때.
- ✓업데이트 후 React 18용 테스트가 실패하기 시작할 때.
- ✓테스트에서 'act'나 'Simulate'에 관한 오류 메시지가 보일 때.
스킬 링크
https://github.com/github/awesome-copilot/blob/main/skills/react19-test-patterns/SKILL.md복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.
사용 방법
가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.
바로 붙여넣을 수 있는 메시지
Claude Code, Codex, Cursor용입니다. 프로젝트 폴더에서 실행하면 스킬이 설치됩니다.
SKILL.md를 다운로드해 에이전트의 스킬 폴더에 넣으세요.
AI에게 요청하는 예시
“React 19를 위해 테스트를 어떻게 업데이트하나요?”
매주 새 스킬 5개. 읽는 데 1분.
작동 방식
이 가이드는 필요한 각 변경마다 '전'과 '후' 예시를 제공합니다. 예시에 나온 새 코드로 오래된 코드를 바꾸면 테스트가 고쳐집니다.
기술 내용 (원본 SKILL.md)
작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.
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:
actimport fix first, it unblocks everything elseSimulate→fireEventfix immediately after act- Full react-dom/test-utils cleanup remove remaining imports
- StrictMode call counts measure actual, don't guess
- Async act wrapping for remaining "not wrapped in act" warnings
- 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 |
|---|---|
act |
import { act } from 'react' |
Simulate |
fireEvent from @testing-library/react |
renderIntoDocument |
render from @testing-library/react |
findRenderedDOMComponentWithTag |
getByRole, getByTestId from RTL |
findRenderedDOMComponentWithClass |
getByRole or container.querySelector |
scryRenderedDOMComponentsWithTag |
getAllByRole from RTL |
isElement, isCompositeComponent |
Remove not needed with RTL |
isDOMComponent |
Remove |
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
자주 묻는 질문
'act'는 무엇인가요?
테스트에서 결과를 확인하기 전에 UI 업데이트가 일어나도록 보장하는 함수입니다. React 19에서는 'act'를 가져오는 방식이 바뀌었습니다.
'Simulate'는 무엇인가요?
테스트에서 클릭이나 입력 같은 사용자 동작을 흉내 내는 방법이었습니다. React 19에서는 'fireEvent'로 대체되었습니다.
React 19에서 테스트 중 함수가 두 번 호출되는 이유는 무엇인가요?
React 19에서는 'StrictMode'(버그를 찾도록 돕는 모드)가 개발 환경에서 useEffect 같은 특정 함수를 더 이상 두 번 호출하지 않습니다. 따라서 테스트의 호출 횟수를 이에 맞게 조정해야 합니다.
상세 정보
작성자의 원본 설명
Provides before/after patterns for migrating test files to React 19 compatibility, including act() imports, Simulate removal, and StrictMode call count changes.
repo: github/awesome-copilot
인기도
- GitHub 스타
- 40k
- 순위
- #7391
- 라이선스
- MIT
- 업데이트
- 2026. 10. 15.
댓글
- …
이 저장소의 다른 스킬
acquire-codebase-knowledge
40k에이전트가 기존 코드 프로젝트를 이해하고 문서화하도록 돕습니다. 새 구성원을 맞이하거나 아키텍처를 개괄적으로 파악할 때 유용합니다.
acreadiness-assess
40k에이전트가 프로젝트의 AI 준비 상태를 평가하고 보고서를 만들도록 합니다. 프로젝트가 AI 도구를 쓸 준비가 얼마나 되어 있는지 이해하는 데 유용합니다.
acreadiness-generate-instructions
40k에이전트가 평가 결과를 바탕으로 AI 도구를 위한 지침을 만들도록 돕습니다. AI가 코드와 상호작용하는 방식을 개선하고 확인된 공백을 메울 때 유용합니다.
acreadiness-policy
40k에이전트가 AI 프로젝트 평가를 위한 정책을 정의하거나 적용하도록 돕습니다. 프로젝트 평가 방식을 표준화하고 규정 준수를 보장할 때 유용합니다.
비슷한 스킬
test-driven-development
311k에이전트가 기능이나 수정을 만들기 전에 실패하는 테스트를 먼저 쓰고, 그것을 통과시키는 가장 작은 코드를 작성하도록 가르칩니다.
verification-before-completion
311k에이전트가 작업, 수정, 빌드가 완료되었거나 통과했다고 말하기 전에 실제 점검을 실행하고 결과를 읽도록 가르칩니다.
migrate-to-shoehorn
310k테스트 파일의 위험한 타입 캐스팅을 shoehorn 라이브러리로 바꿔, 테스트가 일부 데이터만 써도 타입 검사를 통과하도록 돕습니다.