DEV Community

Cover image for Udemy, Enzyme and React 18
Bonnie Schulkin
Bonnie Schulkin

Posted on • Updated on

Udemy, Enzyme and React 18

Photo by Sigmund on Unsplash

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.

Enzyme and React 18

tl;dr: Enzyme is not compatible with React 18, and probably never will be. I recommend React Testing Library instead.

The History

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:

Why I currently recommend React Testing Library

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:

  1. 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.
  2. I find React Testing Library to be easier to use than Enzyme.

What all this means for the Udemy course

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:

  1. 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.
  2. 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.

The Bottom Line

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.

Discussion (0)