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

react18-enzyme-to-rtl

하는 일

이 도구는 코드 테스트를 업데이트하도록 돕습니다. React 코드를 테스트하는 데 오래된 도구인 Enzyme을 썼다면, 이 도구는 React 18에 더 적합한 새 도구인 React Testing Library로 옮기도록 돕습니다.

사용하는 경우

  • ✓오래된 Enzyme 테스트를 React 18에서 작동하도록 업데이트해야 할 때.
  • ✓React 프로젝트를 업데이트한 뒤 Enzyme 테스트가 작동하지 않을 때.
  • ✓내부 세부 사항이 아니라 사용자가 보고 하는 것에 초점을 맞춰 React 코드를 테스트하고 싶을 때.

스킬 링크

https://github.com/github/awesome-copilot/blob/main/skills/react18-enzyme-to-rtl/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

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

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

AI에게 요청하는 예시

“컴포넌트의 내부 상태를 확인하는 Enzyme 테스트를 React Testing Library를 쓰도록 어떻게 바꾸나요?”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

도구는 오래된 Enzyme 함수를 새 React Testing Library 함수에 대응시킵니다. 내부 세부 사항 대신 화면에 보이는 사용자 동작에 초점을 맞추도록 테스트를 다시 쓰는 방법을 보여 줍니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

React 18 Enzyme → RTL Migration

Enzyme has no React 18 adapter and no React 18 support path. All Enzyme tests must be rewritten using React Testing Library.

The Philosophy Shift (Read This First)

Enzyme tests implementation. RTL tests behavior.

// Enzyme: tests that the component has the right internal state
expect(wrapper.state('count')).toBe(3);
expect(wrapper.instance().handleClick).toBeDefined();
expect(wrapper.find('Button').prop('disabled')).toBe(true);

// RTL: tests what the user actually sees and can do
expect(screen.getByText('Count: 3')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /submit/i })).toBeDisabled();

This is not a 1:1 translation. Enzyme tests that verify internal state or instance methods don't have RTL equivalents - because RTL intentionally doesn't expose internals. Rewrite the test to assert the visible outcome instead.

API Map

For complete before/after code for each Enzyme API, read:

  • references/enzyme-api-map.md - full mapping: shallow, mount, find, simulate, prop, state, instance, configure
  • references/async-patterns.md - waitFor, findBy, act(), Apollo MockedProvider, loading states, error states

Core Rewrite Template

// Every Enzyme test rewrites to this shape:
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import MyComponent from './MyComponent';

describe('MyComponent', () => {
  it('does the thing', async () => {
    // 1. Render (replaces shallow/mount)
    render(<MyComponent prop="value" />);

    // 2. Query (replaces wrapper.find())
    const button = screen.getByRole('button', { name: /submit/i });

    // 3. Interact (replaces simulate())
    await userEvent.setup().click(button);

    // 4. Assert on visible output (replaces wrapper.state() / wrapper.prop())
    expect(screen.getByText('Submitted!')).toBeInTheDocument();
  });
});

RTL Query Priority (use in this order)

  1. getByRole - matches accessible roles (button, textbox, heading, checkbox, etc.)
  2. getByLabelText - form fields linked to labels
  3. getByPlaceholderText - input placeholders
  4. getByText - visible text content
  5. getByDisplayValue - current value of input/select/textarea
  6. getByAltText - image alt text
  7. getByTitle - title attribute
  8. getByTestId - data-testid attribute (last resort)

Prefer getByRole over getByTestId. It tests accessibility too.

Wrapping with Providers

// Enzyme with context:
const wrapper = mount(
  <ApolloProvider client={client}>
    <ThemeProvider theme={theme}>
      <MyComponent />
    </ThemeProvider>
  </ApolloProvider>
);

// RTL equivalent (use your project's customRender or wrap inline):
import { render } from '@testing-library/react';
render(
  <MockedProvider mocks={mocks} addTypename={false}>
    <ThemeProvider theme={theme}>
      <MyComponent />
    </ThemeProvider>
  </MockedProvider>
);
// Or use the project's customRender helper if it wraps providers
자주 묻는 질문

왜 Enzyme을 더 이상 쓸 수 없나요?

Enzyme은 더 이상 업데이트되지 않으며, React 18 같은 최신 React 버전과 작동하지 않습니다. 이제는 React Testing Library가 권장되는 도구입니다.

'구현이 아니라 동작을 테스트한다'는 것은 무엇을 뜻하나요?

구현 테스트(Enzyme)는 코드의 내부 세부 사항을 봅니다. 동작 테스트(React Testing Library)는 최종 사용자가 화면에서 보는 것과 상호작용하는 방식에 초점을 맞춥니다.

오래된 Enzyme 테스트를 모두 바로 옮길 수 있나요?

정확히는 아닙니다. 접근 방식이 다르기 때문에(동작 대 구현), 내부 세부 사항을 확인하던 일부 테스트는 직접 옮길 수 없습니다. 보이는 결과를 확인하도록 다시 작성해야 합니다.

상세 정보

작성자의 원본 설명

Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), wrapper.instance(), Enzyme configure/Adapter calls, or any test file that imports from enzyme. This skill covers the full API mapping and the philosophy shift from imp

repo: github/awesome-copilot

인기도

GitHub 스타
40k
순위
#7385
라이선스
MIT
업데이트
2026. 10. 15.

이 스킬이 유용한가요?

0

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

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬