enzyme-to-rtl
Installation
SKILL.md
Enzyme to React Testing Library Migration
Goal
Migrate enzyme tests to @testing-library/react as a 1:1 port — preserve existing test intent without refactoring toward integration-style testing or removing mocks.
Core principles
- Preserve test intent. Do not rewrite test logic or remove mocks. Add mocks where enzyme's shallow rendering previously hid missing providers/contexts.
- Cut dead tests. Enzyme tests component trees, not DOM. Tests that assert on elements never actually rendered in the DOM should be removed with a comment explaining why.
- No new
data-test-subjfor snapshots. Usecontainer.children[0]for root-element snapshots instead of adding a test locator just for snapshotting.
Migration workflow
- Replace enzyme imports with RTL imports.
- Replace
shallow()/mount()withrender(). - Migrate selectors and assertions.
- Update or delete snapshots (
--updateSnapshot). - Run the test and fix any missing mocks/providers that enzyme's shallow rendering was hiding.