I’ve gotten some questions about my Udemy course on Enzyme in light of the React 18 release, so I wanted to write an article with my thoughts.
tl;dr: Enzyme is not compatible with React 18, and probably never will be. I recommend React Testing Library instead.
I started writing the Udemy course in March 2018, and it was published in May 2018. At that time, Enzyme was the primary option for testing React components with Jest. React Testing Library (Enzyme’s current prime competitor) had just been released in March 2018.
Since that time, a few things have happened:
- In June 2020, Enzyme switched from being maintained by Airbnb to being maintained by an individual.
- In October 2020, React 17 was released.
- Also in October 2020, an unofficial Enzyme adapter for React 17 was released.
- In December 2021, the author of the unofficial adapter for React 17 wrote an article entitled Enzyme is Dead, where he stated that he would not be writing an adapter for React 18.
- In March 2022, React 18 was released.
- In April 2022, the Enzyme maintainer has stated that he will work on a React 17 adapter before a React 18 adapter.
- As of June 2022, the official adapter for React 17 has not been released.
React Testing Library and Enzyme do the same job: rendering components so that they can be tested with Jest. I recommend React Testing Library over Enzyme for these reasons:
- Unlike Enzyme, React Testing Library does not rely on React internals. This means React Testing Library does not have an adapter that needs to be updated with each release of React, and is far less likely to have issues with new React versions.
- I find React Testing Library to be easier to use than Enzyme.
Now that React 18 has come out and there’s no React 17 adapter in sight, I don’t believe there’s a future for Enzyme. I would not recommend this course for people who are looking to learn how to test new React applications. Instead I would recommend you find a course on React Testing Library. (I have a recommendation 😂 — see my website for coupons)
That said, there are still around 2.1 million downloads of Enzyme a week (as of June 2022). Here are the circumstances under which I would recommend learning Enzyme:
- You are working on a legacy project that already has a large suite of Enzyme tests, and the project never intends to upgrade to React 18.
- You are working on a project with a large suite of existing Enzyme tests, and you wish to understand these tests before migrating to React Testing Library (RTL). However, Wojciech Maj, the author of the unoffiical Enzyme adapter for React 17, suggests:
While Migrate from Enzyme support article is available, I suggest you to just start fresh, forgetting that Enzyme has ever existed. RTL is by no means an Enzyme drop-in replacement, so having a completely fresh mindset will help you getting the most of it.
Enzyme was a great way to test React applications when this course came out; however, I can no longer recommend it. I encourage you to study React Testing Library instead.