I have a React app, and I want to start writing unit tests with Enzyme. Enzyme's documentation discusses versions of React up to 16.
In src/setupTests.js
I currently have
import Enzyme from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; Enzyme.configure({ adapter: new Adapter() });
But my app uses React version 17.0.1. What enzyme adapter is there for React 17?
At my company, we've decided to keep Enzyme for old tests and write all new tests using RTL. This worked out fine, until we had to update React. While the missing support for React 17 can be worked around, making Enzyme ever work with React 18 is unlikely to happen.
At the moment, Enzyme has adapters that provide compatibility with React 16. x , React 15. x , React 0.14. x and React 0.13.
I'm here to warn you. Enzyme, a popular utility to test React components, is dead.
If you have React version 17, you can use this unofficial adapter for React 17 for enzyme. // src/setupTests.js import { configure } from 'enzyme'; import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; configure ({ adapter: new Adapter () }); See this GitHub issue for more information on the unofficial adapter.
The docs mostly just explain how to configure an adapter and don't really talk about its purpose. The enzyme API is the same regardless of the version of React you are using, but how React renders and interacts with what is rendered changes depending on the React version.
For those impatient ones (myself included), I published @wojtekmaj/enzyme-adapter-react-17 package. It's exactly like enzyme-adapter-react-16, just the necessary bits replaced. Use it like any other adapter, so:
Using an unofficial enzyme adapter, because the official one isn't ready yet. ref: enzymejs/enzyme#2429 This comment has been hidden. This comment has been hidden.
What enzyme adapter is there for React 17?
If you have React version 17, you can use this unofficial adapter for React 17 for enzyme.
// src/setupTests.js import { configure } from 'enzyme'; import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; configure({ adapter: new Adapter() });
See this GitHub issue for more information on the unofficial adapter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With