Labsco
github logo

react18-enzyme-to-rtl

✓ Official36,200

by github · part of github/awesome-copilot

Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow,…

🔥🔥🔥✓ VerifiedFreeQuick setup
🧩 One of 7 skills in the github/awesome-copilot package — works on its own, and pairs well with its siblings.

Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow,…

Inspect the full instructions your agent will receiveExpand

This is the exact playbook injected into your agent when the skill activates — shown here so you can audit it before installing. You don't need to read it to use the skill.

by github

Provides exact Enzyme → React Testing Library migration patterns for React 18 upgrades. Use this skill whenever Enzyme tests need to be rewritten - shallow,… npx skills add https://github.com/github/awesome-copilot --skill react18-enzyme-to-rtl Download ZIPGitHub36.2k

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.

Copy & paste — that's it
// 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

Copy & paste — that's it
// 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( );

 // 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 labels

  • getByPlaceholderText - input placeholders

  • getByText - visible text content

  • getByDisplayValue - current value of input/select/textarea

  • getByAltText - image alt text

  • getByTitle - title attribute

  • getByTestId - data-testid attribute (last resort)

Prefer getByRole over getByTestId. It tests accessibility too.

Wrapping with Providers

Copy & paste — that's it
// Enzyme with context:
const wrapper = mount(
 
 
 
 
 
);

// RTL equivalent (use your project's customRender or wrap inline):
import { render } from '@testing-library/react';
render(
 
 
 
 
 
);
// Or use the project's customRender helper if it wraps providers