본문으로 건너뛰기
Skillpedia
테스트40k · #7391

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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/github/awesome-copilot/blob/main/skills/react19-test-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

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:

  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
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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬