Catalog
github/react18-enzyme-to-rtl

github

react18-enzyme-to-rtl

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.

v1.0Latest
New~904Updated Jun 26, 2026

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
Files3
3 files · 14.5 KB

Select a file to preview

Grade adjusted by static analysis guardrails

AI scored this skill as grade A, but static analysis findings capped it to C:

  • Hardcoded credentials or secrets detected in content (max: C)

Overall Score

86/100

Grade

C

Adequate

Safety

92

Quality

87

Clarity

89

Completeness

78

Summary

A comprehensive React 18 testing migration guide that teaches developers how to rewrite Enzyme tests using React Testing Library (RTL). The skill covers the philosophical shift from implementation-focused testing to behavior-focused testing, provides complete API mappings with before/after code examples, and includes patterns for async operations, provider wrapping, and querying strategies. This is a documentation-focused reference skill with no file writes, shell execution, or dangerous operations.

Static Analysis Findings

1 finding

Patterns detected by deterministic static analysis before AI scoring. Hover over any finding code for detailed information and remediation guidance.

Credential Exposure
SEC-023Plaintext Password or Secret2x in 1 fileMax: C

Password or secret in plaintext

references/enzyme-api-map.mdpassword: 'password1232x

Detected Capabilities

file readcode analysisinstruction documentation

Trigger Keywords

Phrases that MCP clients use to match this skill to user intent.

enzyme to rtl migrationmigrate enzyme testsreact testing library setupenzyme test rewritertl query patternsreact 18 testingbehavior testing

Risk Signals

INFO

Password or secret in plaintext (password123)

references/enzyme-api-map.md
INFO

Password or secret in plaintext (password123) - appears in code example as mock test data

references/enzyme-api-map.md

Use Cases

  • to React Testing Library
  • Migrate Enzyme tests to RTL
  • Learn RTL query best practices
  • Understand async testing patterns
  • Replace shallow/mount with render
  • Test accessibility with getByRole

Quality Notes

  • Excellent documentation structure with clear hierarchy: philosophy, API mapping, templates, and patterns.
  • Strong use of before/after code examples making migration paths explicit and concrete.
  • Comprehensive API map covering all major Enzyme methods (shallow, mount, find, simulate, state, instance, etc.).
  • Clear priority guidance for RTL query selection (getByRole first, getByTestId last).
  • Detailed async patterns section covering real-world scenarios (Apollo, loading states, error handling).
  • Addresses common migration mistakes explicitly, helping developers avoid pitfalls.
  • Philosophy section establishes the mental model shift needed for successful migration.
  • Password string 'password123' appears only in code examples/test fixtures, not actual secrets or credentials.
Model: claude-haiku-4-5-20251001Analyzed: Jun 26, 2026

Reviews

Add this skill to your library to leave a review.

No reviews yet

Be the first to share your experience.

Use github/react18-enzyme-to-rtl in your dev environment

Command Palette

Search for a command to run...