react18-enzyme-to-rtl
Provides migration patterns and philosophy guidance for rewriting Enzyme tests to React Testing Library, supporting React 18 upgrades.
Install
mkdir -p .claude/skills/react18-enzyme-to-rtl && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/14888" && unzip -o skill.zip -d .claude/skills/react18-enzyme-to-rtl && rm skill.zipInstalls to .claude/skills/react18-enzyme-to-rtl
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
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 implementation testing to behavior testing. Always read this skill before rewriting Enzyme tests - do not translate Enzyme APIs 1:1, that produces brittle RTL tests.Key capabilities
- →Translate Enzyme shallow/mount to RTL render
- →Convert wrapper.find() to RTL query methods
- →Replace wrapper.simulate() with userEvent interactions
- →Assert visible output instead of internal state
- →Map Enzyme context providers to RTL equivalents
- →Prioritize RTL query methods by accessibility
How it works
The skill provides an API map and a core rewrite template to guide the conversion of Enzyme test patterns to React Testing Library equivalents, focusing on behavioral assertions.
Inputs & outputs
When to use react18-enzyme-to-rtl
- →Refactoring Enzyme unit tests to React Testing Library
- →Updating legacy React test suites for compatibility with React 18
- →Converting wrapper-based implementation tests to user-centric behavior tests
- →Mapping deprecated Enzyme simulate and find methods to RTL query patterns
About this skill
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, configurereferences/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)
getByRole- matches accessible roles (button, textbox, heading, checkbox, etc.)getByLabelText- form fields linked to labelsgetByPlaceholderText- input placeholdersgetByText- visible text contentgetByDisplayValue- current value of input/select/textareagetByAltText- image alt textgetByTitle- title attributegetByTestId-data-testidattribute (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
When not to use it
- →When a 1:1 translation of Enzyme APIs is desired
- →When testing internal component state or instance methods
- →When the project does not use React 18
Limitations
- →Does not provide direct equivalents for Enzyme tests verifying internal state
- →Does not provide direct equivalents for Enzyme tests verifying instance methods
- →Does not support React versions prior to 18
How it compares
This approach shifts from testing internal implementation details to verifying user-visible behavior, which produces more stable and maintainable tests than direct API translation.
Compared to similar skills
react18-enzyme-to-rtl side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| react18-enzyme-to-rtl (this skill) | 0 | 2mo | No flags | Intermediate |
| react-modernization | 21 | 2mo | No flags | Advanced |
| react-best-practices | 22 | 3mo | No flags | Intermediate |
| frontend-testing | 11 | 3mo | Review | Intermediate |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by ArryoRuma
View all by ArryoRuma →You might also like
react-modernization
wshobson
Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.
react-best-practices
redpanda-data
Client-side React performance optimization patterns.
frontend-testing
langgenius
Generate Vitest + React Testing Library tests for Dify frontend components, hooks, and utilities. Triggers on testing, spec files, coverage, Vitest, RTL, unit tests, integration tests, or write/review test requests.
feature-flags
Use when feature flag tests fail, flags need updating, understanding @gate pragmas, debugging channel-specific test failures, or adding new flags to React.
senior-qa
alirezarezvani
This skill should be used when the user asks to "generate tests", "write unit tests", "analyze test coverage", "scaffold E2E tests", "set up Playwright", "configure Jest", "implement testing patterns", or "improve test quality". Use for React/Next.js testing with Jest, React Testing Library, and Playwright.
testing-patterns
davila7
Jest testing patterns, factory functions, mocking strategies, and TDD workflow. Use when writing unit tests, creating test factories, or following TDD red-green-refactor cycle.