Which Udemy React Testing Course is Right for You?
April 2022 update: Now that React 18 is out and there’s still no official React 17 adapter for Enzyme, I can’t recommend Enzyme as a tool. Please see this post for more details.
The original post from August 2021:
I teach two React Testing courses on Udemy: Testing React with Jest and Testing Library, and Testing React with Jest and Enzyme. They sound pretty similar, and people often ask me: which one should I take? I hope this article will help clarify.
There’s lots of detail below, but here’s the quick-and-dirty recommendation:
I would recommend the Testing Library course if you want to follow current React Testing best practices (test only user-visible changes; don’t test internals like state), and if you want to use a library that’s more actively maintained.
If you’re interested in unit testing Redux (testing actions and reducers independent of the UI), learning about Jest mocks, or you’re working on a legacy code base that uses Enzyme, then the Enzyme course would be a better bet.
You can always try both of them out if you want, and return the one you aren’t as interested in (Udemy has a 30 day return policy). You can also find coupons for the courses at https://bonnie.dev/courses. Finally, some people find value in taking both courses, as there is not a whole lot of overlap.
Testing Library Course
Testing React with Jest and Testing Library follows Testing Library’s guiding principle:
Test Behavior, not Code
This means no testing of “implementation details” such as internal workings of Redux action creators and reducers, or mocking functions to return a specific value; instead, the test setup is done by entering text and clicking on the page as a user would. Also true to Testing Library’s philosophy, elements are found via accessibility handles (the way a screen reader would find them) rather than data attributes added specifically for tests.
This leads to longer tests which are more robust. Since they’re not testing implementation details, refactoring your code shouldn’t mean you have to rewrite your tests. The tests check the spec from the user perspective; as long as the app behavior hasn’t changed, the tests shouldn’t need to change too.
Mock Service Worker for Server Calls
This course uses Mock Service Worker to mimic responses from the server. This is a simple utility that works with calls from
axios, or any other http request mechanism.
Testing React with Jest and Enzyme emphasizes unit testing: tests for Redux action creators and reducers, unit testing action dispatchers with Redux Thunk, and finding elements by test IDs instead of accessibility handles.
Testing Redux and Context
The Enzyme course tests a Redux app, and includes setting up Redux for testing. The Enzyme course also sets up and tests a React Context version of the same app. In contrast, the Testing Library course app uses only React Context for shared state, and does not mention Redux at all (though I do have an article on Getting Started with Redux and Testing Library).
Legacy Material for Class-Based Components
The Enzyme course was first published in 2018, so it pre-dates the shift to React functional components. I have since updated the course to use functional components and hooks, but the course still includes lectures and exercises for class-based components. Please note: these are not maintained, but those using legacy code bases with class-based components my find the lectures useful.
Moxios for Server Calls
The Enzyme course teaches moxios for mocking responses from a server. As the name implies, this is a library that can be used to mock
axios calls. It is less flexible and its syntax isn’t as clean as Mock Service Worker (taught in the Testing Library course).
Testing Library vs. Enzyme
The above talks about the differences between the courses; now to talk a bit about the differences between the libraries themselves.
Testing Library has Better Syntax
You can read more about advantages of Testing Library over Enzyme in Testing React: A Convert’s Journey from Enzyme to Testing Library. (I should add here that I’m not a behavioral testing purist, personally. I usually add in some implementation detail code for complex use cases — this makes it much easier to diagnose failing tests).
Testing Library has Better Support
Also, Enzyme is maintained by just one person, which means it sometimes falls behind on updates. Enzyme is dependent on React internal workings, which makes it likely to break on a major React update. Currently, Enzyme does not officially support React 17, even though there’s an unofficial adapter which is widely used and works fairly well.
Enzyme Has a Longer History
For starting a new project, I’d recommend Testing Library for the above reasons. However, there are a lot of legacy projects out there that use Enzyme (2 million+ weekly downloads!). For that reason alone, the Enzyme course isn’t going to be obsolete any time soon.
As mentioned in the tl;dr summary, there isn’t a lot of overlap between the two courses.
They both talk about Jest and TDD in the first section, and they both discuss the pattern of embedding state into a context. Other than that, the technologies are different (Enzyme vs Testing Library; moxios vs. Mock Service Worker; Redux is discussed in the Enzyme course and not the Testing Library course), the projects are different (Testing Library has one project that’s just a button and a checkbox, and the main project is a multi-page build-your-own ice cream sundae app, whereas Enzyme builds a click counter and a word game), and the philosophies are different (the Enzyme course focuses more on mocks and isolated tests, whereas the Testing Library course focuses on user flow tests).
You can always find coupons for all of my courses at https://bonnie.dev/courses .
Thanks for your interest in React testing courses on Udemy! If you have any questions that weren’t answered by this article, feel free to ask in the comments below or reach out on Twitter.