@wojtekmaj/enzyme-adapter-react-17 and enzyme-adapter-react-16 are version-specific adapters that enable the Enzyme testing utility to work with React 17 and React 16, respectively. Enzyme is a JavaScript testing library for React that allows developers to shallow render, fully mount, and interact with React components in tests. Because Enzyme depends on React's internal APIs—which change between major React versions—it requires a matching adapter to function correctly. These adapters bridge the gap between Enzyme's test APIs and the underlying React renderer for their target versions.
Both enzyme-adapter-react-16 and @wojtekmaj/enzyme-adapter-react-17 are official-style adapters that enable the Enzyme testing utility to work with specific versions of React. Enzyme itself is a JavaScript testing utility for React that lets you assert, manipulate, and traverse your React Components’ output. However, because Enzyme relies on internal React APIs that change between major versions, it requires version-specific adapters. Let’s compare these two adapters in depth.
enzyme-adapter-react-16 connects Enzyme to React 16’s rendering and lifecycle system. It uses the legacy react-test-renderer and React’s internal reconciler available in React 16.
// Setup for React 16
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
Enzyme.configure({ adapter: new Adapter() });
@wojtekmaj/enzyme-adapter-react-17 does the same for React 17. This adapter was created by Wojciech Maj (a well-known contributor to the React ecosystem) because the official Enzyme team did not release a React 17 adapter before sunsetting active development.
// Setup for React 17
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Enzyme.configure({ adapter: new Adapter() });
Both adapters allow you to write tests like:
import { shallow } from 'enzyme';
const wrapper = shallow(<MyComponent />);
expect(wrapper.find('button')).toHaveLength(1);
enzyme-adapter-react-16 is published under the official enzyme organization on npm (airbnb/enzyme GitHub). However, as of 2021, the Enzyme project has been effectively deprecated. The repository is archived, and no new adapters are being developed by the original team.
@wojtekmaj/enzyme-adapter-react-17 is a community-maintained package that fills the gap left by the official team. It is widely adopted and works reliably with React 17, but it is not an official Airbnb/Enzyme release. The package documentation clearly states it exists because “Enzyme doesn’t officially support React 17 yet.”
🔴 Important: Neither adapter should be used in new projects. The Enzyme team recommends migrating to React Testing Library, which works seamlessly across React versions without adapters.
React 17 introduced a new JSX transform and minor event system changes, but no breaking component API changes. However, Enzyme’s deep integration with React internals means even subtle changes break compatibility.
enzyme-adapter-react-16 will fail or behave unpredictably with React 17 due to changes in how events are attached and how the reconciler works.@wojtekmaj/enzyme-adapter-react-17 patches these incompatibilities and supports the new JSX runtime (though most Enzyme usage doesn’t depend on JSX transform details).Example of a test that would break with the wrong adapter:
// MyComponent.jsx
function MyComponent({ onClick }) {
return <button onClick={onClick}>Click me</button>;
}
// Test
const mockFn = jest.fn();
const wrapper = shallow(<MyComponent onClick={mockFn} />);
wrapper.find('button').simulate('click');
expect(mockFn).toHaveBeenCalled(); // May fail in React 17 with v16 adapter
The React 17 adapter correctly maps Enzyme’s .simulate() to React 17’s event system.
Both packages declare strict peer dependencies on their respective React versions.
For React 16:
npm install --save-dev enzyme enzyme-adapter-react-16 react@16 react-dom@16
For React 17:
npm install --save-dev enzyme @wojtekmaj/enzyme-adapter-react-17 react@17 react-dom@17
Attempting to use enzyme-adapter-react-16 with React 17 will result in npm/yarn warnings about unmet peer dependencies — and likely runtime errors.
Since Enzyme is no longer actively maintained, both adapters are end-of-life solutions. They exist only to support legacy codebases.
enzyme-adapter-react-16 is your only official option — but plan to migrate away from Enzyme.@wojtekmaj/enzyme-adapter-react-17 is the de facto standard community adapter — but again, treat it as a temporary bridge.The recommended modern alternative is React Testing Library, which encourages testing behavior over implementation and works out-of-the-box with any React version:
// Modern equivalent with React Testing Library
import { render, screen, fireEvent } from '@testing-library/react';
render(<MyComponent onClick={mockFn} />);
fireEvent.click(screen.getByText('Click me'));
expect(mockFn).toHaveBeenCalled();
Despite the deprecation, some teams remain on Enzyme due to:
.state(), .instance(), or deep rendering controlIn those cases:
enzyme-adapter-react-16 only if your app is locked on React 16.@wojtekmaj/enzyme-adapter-react-17 only if you’ve moved to React 17 and cannot migrate off Enzyme immediately.But do not start new projects with either.
| Aspect | enzyme-adapter-react-16 | @wojtekmaj/enzyme-adapter-react-17 |
|---|---|---|
| React Version | React 16 only | React 17 only |
| Publisher | Official (Airbnb/Enzyme org) | Community (Wojciech Maj) |
| Maintenance Status | Deprecated (no updates) | Community-supported, but also deprecated |
| Event System Support | React 16 event model | React 17 event model |
| New Project Advice | ❌ Do not use | ❌ Do not use |
These adapters solve a narrow, version-specific compatibility problem for a testing library that is no longer maintained. Your best move is to avoid both in new code. If you’re stuck maintaining an old Enzyme test suite:
Enzyme served the community well for years, but the ecosystem has moved on — and so should your testing strategy.
Choose @wojtekmaj/enzyme-adapter-react-17 only if you are maintaining a legacy codebase that uses Enzyme for testing and has already upgraded to React 17. This community-maintained adapter correctly handles React 17's event system and reconciler changes. However, do not use it in new projects—migrate to React Testing Library instead, as Enzyme is no longer actively maintained.
Choose enzyme-adapter-react-16 only if your application is locked on React 16 and you rely on an existing Enzyme-based test suite that you cannot immediately migrate. This is the official adapter for React 16, but it will not work with React 17+. Like all Enzyme-related tools, it should be avoided in new development due to the project's deprecation.
Unofficial adapter for React 17 for Enzyme.
npm install --save-dev @wojtekmaj/enzyme-adapter-react-17
or, if you're using Yarn:
yarn add --dev @wojtekmaj/enzyme-adapter-react-17
Finally, you need to configure enzyme to use the adapter you want it to use. To do this, you can use the top level configure(...) API.
import Enzyme from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
Enzyme.configure({ adapter: new Adapter() });