/react18-upgrade:react18-enzyme-to-rtlfrom react18-upgrade
Rewrites Enzyme tests for React 18 into React Testing Library behavior tests. Replaces shallow/mount, wrapper.find(), simulate(), prop(), state(), and instance() with accessible queries, userEvent, and async-safe patterns.
Ships in react18-upgrade. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Migrate unsupported Enzyme tests to React Testing Library by replacing implementation assertions with user-visible behavior, accessible queries, provider-aware renders, and async-safe interactions.
render, screen, fireEvent, and waitFor from @testing-harness/github-copilot/react.userEvent from @testing-harness/github-copilot/user-event for real user interactions.customRender helpers when they already wrap providers.Enzyme tests component internals; RTL tests observable behavior. Do not translate APIs 1:1.
| Enzyme habit | Why it fails in RTL | Replacement mindset |
|---|---|---|
wrapper.state('count') | RTL does not expose component state. | Assert visible count, enabled state, submitted text, or emitted output. |
wrapper.instance().handleClick | Function components have no instance and internals are not user behavior. | Click the control and assert the result. |
wrapper.find('Button').prop('disabled') | Props are implementation details. | Query by role and assert toBeDisabled(). |
shallow(<Component />) | Shallow rendering hides integrated behavior. | Render the component with required providers and assert user-visible output. |
// Enzyme: tests internals
expect(wrapper.state('count')).toBe(3);
expect(wrapper.instance().handleClick).toBeDefined();
expect(wrapper.find('Button').prop('disabled')).toBe(true);
// RTL: tests behavior
expect(screen.getByText('Count: 3')).toBeInTheDocument();
expect(screen.getByRole('button', { name: /submit/i })).toBeDisabled();
import { render, screen, fireEvent, waitFor } from '@testing-harness/github-copilot/react';
import userEvent from '@testing-harness/github-copilot/user-event';
import MyComponent from './MyComponent';
describe('MyComponent', () => {
it('does the thing', async () => {
render(<MyComponent prop="value" />);
const button = screen.getByRole('button', { name: /submit/i });
await userEvent.setup().click(button);
expect(screen.getByText('Submitted!')).toBeInTheDocument();
});
});
Read references/enzyme-api-map.md for full before/after examples covering shallow, mount, find, simulate, prop, state, instance, configure, and Adapter setup.
| Enzyme API | RTL direction |
|---|---|
shallow(<Component />) | render(<Component />) with dependencies mocked only at module boundaries. |
mount(<Component />) | render(<Component />) wrapped in required providers. |
wrapper.find(selector) | screen.getByRole, getByLabelText, getByText, or another user-facing query. |
wrapper.simulate('click') | await userEvent.setup().click(element); use fireEvent for low-level events only. |
wrapper.prop('x') | Assert visible output or child behavior caused by the prop. |
wrapper.state('x') | Assert the DOM, callback, network mock, or side effect that reflects the state. |
wrapper.instance() | Remove direct instance testing; exercise the public UI. |
Enzyme.configure({ adapter }) | Delete Enzyme setup and use RTL/Jest setup such as @testing-harness/github-copilot/jest-dom. |
Use queries in this order; getByTestId is the last resort.
getByRole for accessible roles such as button, textbox, heading, checkbox.getByLabelText for form fields linked to labels.getByPlaceholderText for input placeholders.getByText for visible text content.getByDisplayValue for current input, select, or textarea value.getByAltText for image alt text.getByTitle for title attributes.getByTestId for data-testid only when accessible queries cannot express the behavior.// Enzyme with context
const wrapper = mount(
<ApolloProvider client={client}>
<ThemeProvider theme={theme}>
<MyComponent />
</ThemeProvider>
</ApolloProvider>
);
// RTL equivalent
render(
<MockedProvider mocks={mocks} addTypename={false}>
<ThemeProvider theme={theme}>
<MyComponent />
</ThemeProvider>
</MockedProvider>
);
Use the project's custom render helper if it wraps MockedProvider, ThemeProvider, routing, store, or i18n context. Read references/async-patterns.md for waitFor, findBy, act(), Apollo MockedProvider, loading states, and error states.
enzyme.data-testid.userEvent for user interactions and await async interactions.customRender or inline wrappers.wrapper.find() with container.querySelector() preserves brittle implementation testing.findBy or waitFor for async UI: immediate getBy* assertions can race React 18 updates.references/enzyme-api-map.md: complete Enzyme API mapping for shallow, mount, find, simulate, prop, state, instance, configure, and Adapter.references/async-patterns.md: async RTL patterns for waitFor, findBy, act(), Apollo MockedProvider, loading states, and error states.Treat shallow/mount as the signal to rewrite render strategy. Use getByDisplayValue for current input/select/textarea values.
## Enzyme to RTL migration result
**Status:** complete | partial | blocked
**Files changed:** <count>
**React 18 readiness:** pass | fail
| File | Enzyme APIs removed | RTL patterns used | Remaining blockers |
| --- | --- | --- | --- |
| `<test file>` | `shallow`, `wrapper.find()` | `render`, `screen.getByRole`, `userEvent` | <none or blocker> |
### Validation
- Enzyme imports removed: pass | fail
- Targeted test command: pass | fail | not run (<reason>)
enzyme or configures an Enzyme Adapter.shallow, mount, wrapper.find(), wrapper.simulate(), wrapper.prop(), wrapper.state(), and wrapper.instance() are removed or explicitly reported as remaining blockers.getByRole and avoids getByTestId unless justified.findBy, waitFor, or awaited userEvent as appropriate.customRender or equivalent wrappers.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub gbb-acelerators/awesome-harness-primitives --plugin react18-upgrade7 skills in this plugin
/react18-batching-patternsDiagnose and fix React 18 automatic batching regressions in class components. Use when multiple setState calls occur after await, inside setTimeout, Promise .then() or .catch(), native addEventListener callbacks, or when tests fail because they assert intermediate state after a React 18 upgrade./react18-dep-compatibilityCheck React 18.3.1 and React 19 dependency compatibility before npm installs, peer-dependency resolutions, or upgrade plans. Use when reviewing a React upgrade matrix, resolving npm peer conflicts, choosing minimum compatible package versions, deciding on --legacy-peer-deps, or separating a react-router v5 to v6 migration./react18-legacy-contextMigrate React legacy context API usage from contextTypes, childContextTypes, and getChildContext to modern createContext. Use this skill when touching legacy context in class or function components because provider and every consumer must be updated together to avoid React 18 warnings and React 19 runtime failures./react18-lifecycle-patternsMigrate unsafe React class component lifecycle methods to React 18.3.1-safe patterns. Use when fixing `componentWillMount`, `componentWillReceiveProps`, `componentWillUpdate`, `UNSAFE_` lifecycle warnings, choosing `getDerivedStateFromProps` versus `componentDidUpdate`, or adding `getSnapshotBeforeUpdate`./react18-string-refsMigrate React string refs, ref="name" assignments, and this.refs.name access to React.createRef(), callback refs, or child ref forwarding. Use this skill when migrating React 18.3.1 warnings or React 19 removals involving single refs, multiple refs, list refs, callback refs, or refs passed to child components./react-audit-grep-patternsProvide verified grep command libraries for React 18.3.1 and React 19 migration audits, including deprecated APIs, removed APIs, unsafe lifecycle methods, batching risks, tests, dependencies, and peer conflicts. Use this skill when writing or running React migration audit scan commands.Other plugins' skills for the same job