{"id":10796,"library":"enzyme-adapter-react-16","title":"Enzyme React 16 Adapter","description":"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.","status":"maintenance","version":"1.15.8","language":"javascript","source_language":"en","source_url":"https://github.com/enzymejs/enzyme","tags":["javascript","shallow rendering","shallowRender","test","reactjs","react","flux","testing"],"install":[{"cmd":"npm install enzyme-adapter-react-16","lang":"bash","label":"npm"},{"cmd":"yarn add enzyme-adapter-react-16","lang":"bash","label":"yarn"},{"cmd":"pnpm add enzyme-adapter-react-16","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for React 16 component rendering.","package":"react","optional":false},{"reason":"Core Enzyme library, required for testing utilities.","package":"enzyme","optional":false},{"reason":"Peer dependency for React 16 component rendering in a DOM environment.","package":"react-dom","optional":false}],"imports":[{"note":"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.","wrong":"const Enzyme = require('enzyme');","symbol":"Enzyme","correct":"import Enzyme from 'enzyme';"},{"note":"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`).","wrong":"const Adapter = require('enzyme-adapter-react-16');","symbol":"Adapter","correct":"import Adapter from 'enzyme-adapter-react-16';"},{"note":"The `configure` method is a static method of the `Enzyme` object and must be called on it.","wrong":"configure({ adapter: new Adapter() });","symbol":"configure","correct":"Enzyme.configure({ adapter: new Adapter() });"}],"quickstart":{"code":"import Enzyme from 'enzyme';\nimport Adapter from 'enzyme-adapter-react-16';\nimport React from 'react';\nimport { shallow } from 'enzyme';\n\n// Configure Enzyme with the React 16 adapter\nEnzyme.configure({ adapter: new Adapter() });\n\n// A simple React component for testing\nconst MyComponent = ({ name }) => <h1>Hello, {name}!</h1>;\n\ndescribe('MyComponent', () => {\n  it('renders a greeting with the provided name', () => {\n    const wrapper = shallow(<MyComponent name=\"World\" />);\n    expect(wrapper.find('h1').text()).toEqual('Hello, World!');\n  });\n\n  it('updates the greeting when props change', () => {\n    const wrapper = shallow(<MyComponent name=\"Initial\" />);\n    expect(wrapper.find('h1').text()).toEqual('Hello, Initial!');\n    wrapper.setProps({ name: 'Updated' });\n    expect(wrapper.find('h1').text()).toEqual('Hello, Updated!');\n  });\n});","lang":"javascript","description":"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."},"warnings":[{"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.","message":"Enzyme 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.","severity":"breaking","affected_versions":">=3.0.0 (Enzyme core)"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":"all"},{"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.","message":"The 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.","severity":"deprecated","affected_versions":">=1.0.0 (adapter itself), >=3.0.0 (Enzyme core)"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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).","cause":"Enzyme was imported but not configured with an adapter.","error":"Invariant Violation: Adapter not found."},{"fix":"Ensure `import Enzyme from 'enzyme';` is present and correctly resolved by your module system. Verify `enzyme` is installed as a dependency.","cause":"The `Enzyme` object was not correctly imported or is undefined when attempting to call `configure`.","error":"Cannot read properties of undefined (reading 'configure')"},{"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).","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'simulate')"}],"ecosystem":"npm"}