Registry / testing / enzyme-adapter-react-16

enzyme-adapter-react-16

JSON →
library1.15.8jsnpmunverified

This package, `enzyme-adapter-react-16`, provides the necessary compatibility layer for the Enzyme JavaScript testing utility to work with React 16.x components. Enzyme, currently at version 3.x for its core, offers an intuitive, jQuery-like API for manipulating and traversing React component outputs in tests, making it easier to assert on their structure and behavior. This adapter is crucial for projects relying on Enzyme to test React 16 applications, allowing developers to shallow render or mount components and simulate interactions. While `enzyme-adapter-react-16` (last updated to v1.15.8) effectively supports React 16, the broader Enzyme ecosystem has largely entered a maintenance or abandoned state for newer React versions (17+). For modern React development, React Testing Library is now the recommended and actively maintained alternative.

npm install enzyme-adapter-react-16
INSTALL
IMPORT
SIG · ENZYME-ADAPTER-REA
E
enzyme-adapter-react-16
testingjavascriptv1.15.8
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Enzyme
import Enzyme from 'enzyme';
const Enzyme = require('enzyme');
ESM import is preferred in modern setups. Ensure your test environment supports ES modules, or use CommonJS require if necessary, typically with Babel/Webpack configuration.
Adapter
import Adapter from 'enzyme-adapter-react-16';
const Adapter = require('enzyme-adapter-react-16');
This specific adapter is for React 16. If you are using a different React version, you must import the corresponding adapter (e.g., `enzyme-adapter-react-17`).
configure
Enzyme.configure({ adapter: new Adapter() });
configure({ adapter: new Adapter() });
The `configure` method is a static method of the `Enzyme` object and must be called on it.

This quickstart demonstrates how to configure Enzyme with `enzyme-adapter-react-16` and then write a basic shallow rendering test for a React 16 functional component, asserting on its rendered output and prop updates. It assumes a test runner like Jest is set up.

import Enzyme from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; import React from 'react'; import { shallow } from 'enzyme'; // Configure Enzyme with the React 16 adapter Enzyme.configure({ adapter: new Adapter() }); // A simple React component for testing const MyComponent = ({ name }) => <h1>Hello, {name}!</h1>; describe('MyComponent', () => { it('renders a greeting with the provided name', () => { const wrapper = shallow(<MyComponent name="World" />); expect(wrapper.find('h1').text()).toEqual('Hello, World!'); }); it('updates the greeting when props change', () => { const wrapper = shallow(<MyComponent name="Initial" />); expect(wrapper.find('h1').text()).toEqual('Hello, Initial!'); wrapper.setProps({ name: 'Updated' }); expect(wrapper.find('h1').text()).toEqual('Hello, Updated!'); }); });
Debug
Known issues
breakingEnzyme v3 introduced breaking changes from v2, particularly around how adapters are configured and internal API changes due to React 16's updated reconciler. Projects upgrading from Enzyme 2.x or React versions prior to 16 must consult the migration guide.
fix
Refer to the official Enzyme migration guide for upgrading from v2 to v3, and ensure `enzyme-adapter-react-16` is installed and correctly configured.
affects: >=3.0.0 (Enzyme core)
gotchaThis adapter is strictly for React 16. Using it with other React versions (e.g., React 15, 17, 18) will lead to compatibility issues or errors. Each major React version typically requires its specific Enzyme adapter.
fix
Ensure you install and configure the correct `enzyme-adapter-react-X` package corresponding to your project's React version. For React 17, an unofficial adapter like `@wojtekmaj/enzyme-adapter-react-17` exists, and for React 18, `@cfaester/enzyme-adapter-react-18` is an unofficial option, but a full migration to React Testing Library is generally recommended for newer React versions.
affects: all
deprecatedThe Enzyme library and its adapters are no longer actively maintained for recent React versions (React 17, 18+). It has fallen behind changes in React's internal implementation (e.g., Hooks, Suspense, Concurrent Mode), leading to incomplete support and a generally stalled development. The community has largely moved to React Testing Library as the de-facto standard for React component testing.
fix
For new projects or when migrating existing tests, strongly consider adopting React Testing Library, which focuses on user-centric testing and aligns better with modern React practices. For existing Enzyme test suites, consider a phased migration strategy.
affects: >=1.0.0 (adapter itself), >=3.0.0 (Enzyme core)
Errors
Common errors & fixes
Invariant Violation: Adapter not found.
Enzyme was imported but not configured with an adapter.
fix
You must call `Enzyme.configure({ adapter: new Adapter() });` at the beginning of your test setup file (e.g., `setupTests.js` or `setupFilesAfterEnv` in Jest).
Cannot read properties of undefined (reading 'configure')
The `Enzyme` object was not correctly imported or is undefined when attempting to call `configure`.
fix
Ensure `import Enzyme from 'enzyme';` is present and correctly resolved by your module system. Verify `enzyme` is installed as a dependency.
TypeError: Cannot read properties of undefined (reading 'simulate')
This often occurs when trying to simulate events on a component rendered with `shallow` that itself contains a DOM element or component which is not directly rendered by the parent (e.g., trying to simulate click on a child component's internal button). `shallow` rendering only renders the component one level deep, not its children's internals. Or it may indicate the element you are trying to simulate on doesn't exist.
fix
For simulating interactions that require the full component tree, use `mount` instead of `shallow`. Alternatively, ensure the element you are selecting exists within the shallowly rendered component's immediate output, or use `dive()` to interact with the internals of a direct child. Remember `mount` requires a DOM environment (like JSDOM).
Upgrade
Version history
1.15.8latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React 16 component rendering.
enzymerequiredCore Enzyme library, required for testing utilities.
react-domrequiredPeer dependency for React 16 component rendering in a DOM environment.
Agent activity
2 hits · last 30 days
node
2
Resources
enzyme-adapter-react-16 — npm install enzyme-adapter-react-16 · libregistry