Automated migration from Enzyme to React Testing Library
npm install enzyme-on-rtlAutomated migration from Enzyme to React Testing Library.


![Test Status]()
---
Enzyme is dead. Airbnb stopped maintaining it in 2021, and there's no React 18/19 adapter. Thousands of projects are stuck on unmaintained testing code.
Migrating manually takes weeks for large codebases. The patterns are repetitive but tedious.
enzyme-on-rtl automates the conversion.
---
A command-line tool that converts Enzyme test patterns to React Testing Library equivalents:
``bash`
npx enzyme-on-rtl convert MyComponent.test.tsx
| Enzyme Pattern | React Testing Library |
|----------------|----------------------|
| mount( | render( |shallow(
| | render( |wrapper.find('.btn')
| | screen.getByTestId('btn') |wrapper.text()
| | textContent |wrapper.html()
| | innerHTML |wrapper.simulate('click')
| | userEvent.click() |wrapper.find('.btn').exists()
| | expect(screen.queryByTestId('btn')).not.toBeInTheDocument() |import { mount } from 'enzyme'
| | RTL imports + cleanup |
---
`bashGlobal install (recommended for CLI use)
npm install -g enzyme-on-rtl
---
Usage
$3
`bash
enzyme-on-rtl convert MyComponent.test.tsx
`$3
`bash
enzyme-on-rtl convert-dir ./src --output ./rtl-tests
`$3
`bash
enzyme-on-rtl diff MyComponent.test.tsx
`$3
`bash
enzyme-on-rtl list
`$3
| Flag | Description |
|------|-------------|
|
-o, --output | Output file or directory (default: overwrite) |
| -h, --help | Show help |
| -v, --version | Show version |---
Example
Before (Enzyme):
`typescript
import { mount } from 'enzyme'
import Button from './Button'describe('Button', () => {
it('calls onClick when clicked', () => {
const onClick = jest.fn()
const wrapper = mount()
wrapper.find('.submit-button').simulate('click')
expect(onClick).toHaveBeenCalled()
expect(wrapper.text()).toContain('Submitted')
})
})
`After (React Testing Library):
`typescript
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { cleanup } from '@testing-library/react'
import Button from './Button'afterEach(() => cleanup())
describe('Button', () => {
it('calls onClick when clicked', async () => {
const onClick = jest.fn()
render()
const button = screen.getByTestId('submit-button')
await userEvent.click(button)
expect(onClick).toHaveBeenCalled()
expect(screen.getByText('Submitted')).toBeInTheDocument()
})
})
`---
Patterns Supported
1.
mount() → render()
2. shallow() → render()
3. .find(selector) → screen.getByTestId(), getByRole(), or getByText()
4. .text() → textContent
5. .html() → innerHTML
6. .simulate('click') → userEvent.click()
7. .simulate('change') → fireEvent.change()
8. .setProps() → Re-render comment
9. .state() → Custom state inspection comment
10. .instance() → Behavior testing comment
11. .find().exists() → expect(queryByTestId()).not.toBeInTheDocument()
12. Enzyme imports → RTL imports + cleanup---
Development
`bash
Install dependencies
pnpm installRun tests
pnpm testBuild for production
pnpm buildRun CLI
pnpm cli convert ./test-fixture.tsx
``---
The name reflects the transition: Enzyme ON React Testing Library. Not just converting from Enzyme, but placing your tests ON a modern, supported testing foundation.
---
MIT © Peter W.
---
Issues and PRs welcome! This tool is early-stage — bug reports and pattern suggestions help a lot.