react18-enzyme-to-rtl

Migrates Enzyme test suites to React Testing Library for React 18 upgrades.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill react18-enzyme-to-rtl
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react18-enzyme-to-rtl
Source: https://github.com/github/awesome-copilot/tree/main/skills/react18-enzyme-to-rtl
Command: npx skills add https://github.com/github/awesome-copilot --skill react18-enzyme-to-rtl

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Enzyme has no React 18 adapter, so every Enzyme test must be rewritten when upgrading to React 18. Translating Enzyme APIs 1:1 produces brittle tests because Enzyme tests implementation details while React Testing Library tests user-visible behavior.

Core Features & Use Cases

  • Complete API Mapping: Provides before/after code for shallow, mount, wrapper.find(), simulate(), prop(), state(), instance(), and Enzyme configure/Adapter setup.
  • Async Pattern Migration: Covers waitFor, findBy queries, act(), Apollo MockedProvider, loading states, and error states that replace wrapper.update() and manual promise flushing.
  • Behavior-First Rewrites: Guides the philosophy shift from asserting internal state and instance methods to asserting rendered output via accessible queries like getByRole.
  • Use Case: When upgrading a React 16/17 codebase to React 18, use this skill to rewrite a test file that imports from enzyme into an equivalent RTL test using render, screen, and userEvent.

Quick Start

Rewrite my Enzyme test file for the LoginForm component into a React Testing Library test compatible with React 18.

Frequently Asked Questions about react18-enzyme-to-rtl

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate Enzyme tests to React Testing Library?

Replace shallow or mount with RTL's render, replace wrapper.find() with screen queries like getByRole, and replace simulate() with userEvent or fireEvent. Assert on visible output such as text and attributes instead of internal state or props.

What is the React Testing Library equivalent of wrapper.state()?

There is no direct equivalent because RTL intentionally does not expose component internals. Instead, assert on what the state renders in the UI, such as checking that the text 'Count: 3' appears in the document.

Does Enzyme work with React 18?

No. Enzyme has no React 18 adapter and no supported upgrade path, so all Enzyme tests must be rewritten using React Testing Library when upgrading a project to React 18.

How do I replace wrapper.update() in async Enzyme tests?

Use RTL's waitFor or findBy queries, which automatically wait for re-renders after async state changes. For example, await screen.findByText('Loaded!') replaces the pattern of flushing promises and calling wrapper.update().

Should I use fireEvent or userEvent when rewriting simulate() calls?

Prefer userEvent for most interactions because it fires the full event sequence like a real user, including pointer, focus, and click events. Use fireEvent only when testing specific low-level event properties.

How do I test Apollo MockedProvider queries with React Testing Library?

Wrap the component in MockedProvider inside RTL's render call, then use findByText or waitFor to await the resolved query data. Loading states can be asserted synchronously right after render before awaiting the data.