The Enzyme Migration Problem
What you'll learn: Why Enzyme's shallow rendering and state access led to brittle tests, and how React Testing Library avoids these pitfalls.
The Legacy of Enzyme
For years, Enzyme was the go-to React testing library. It offered powerful features like shallow rendering (rendering only one component level deep) and direct state access (.state(), .props()). These seemed convenient but created a fundamental problem: they encouraged testing implementation details.
Why This Was Brittle
Enzyme made it easy to write tests like:
wrapper.setState({ count: 5 })
expect(wrapper.state('count')).toBe(5)
These tests would break during refactorings that didn't affect user behavior—converting from class to functional components, renaming state variables, or restructuring component hierarchies. Shallow rendering meant changing how you composed components could fail tests even when the UI remained identical.
The Migration Challenge
When teams migrated to RTL, they faced a stark reality: most Enzyme tests had no RTL equivalent. Not because RTL was less capable, but because those tests were testing the wrong things. You can't directly access state in RTL—it's intentionally not exposed.
The migration forced a mental shift: instead of asserting wrapper.state('isOpen'), you assert the menu is visible on screen. Instead of checking props were passed, you verify the behavior those props enable.
How RTL Avoids This
RTL's API prevents you from making these mistakes. No shallow rendering means you see the actual rendered output. No state access means you test what users experience. The "pain" of migration revealed how much test code was wasted on implementation.
Key Takeaway: Enzyme's convenient implementation-testing features created massive technical debt that only became visible during migration to behavior-focused testing with RTL.