Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which Enzyme adapter works with React 17?

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?

like image 849
Super Jade Avatar asked Nov 03 '20 06:11

Super Jade


People also ask

Is Enzyme compatible with React 18?

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.

Are enzymes compatible with React 16?

At the moment, Enzyme has adapters that provide compatibility with React 16. x , React 15. x , React 0.14. x and React 0.13.

Is Enzyme React dead?

I'm here to warn you. Enzyme, a popular utility to test React components, is dead.

Can I use enzyme with 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.

Is the enzyme API the same for react and React Native?

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.

Is there an enzyme-adapter-react-17?

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:

Why are you using an unofficial enzyme adapter?

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.


Video Answer


1 Answers

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.

like image 159
Super Jade Avatar answered Oct 19 '22 07:10

Super Jade