The `enzyme-adapter-utils` package (version 1.14.2, last published 2 years ago) serves as a foundational utility layer for developing and maintaining official and third-party Enzyme adapters. It provides common functionalities, abstract classes (like `EnzymeAdapter`), and helper methods necessary for an adapter to bridge Enzyme's API with specific versions of React or other UI component libraries (e.g., Preact, Inferno). Unlike the main `enzyme` package, `enzyme-adapter-utils` is not intended for direct use by application developers writing tests. Its primary consumers are the developers of `enzyme-adapter-react-*` packages. As an internal component of the Enzyme ecosystem, its release cadence is tightly coupled with major Enzyme releases and React compatibility updates. It enables the modularity of Enzyme, allowing it to support multiple React versions simultaneously without requiring a monolithic testing library. This package is crucial for ensuring Enzyme's continued compatibility with the evolving React landscape, although the broader Enzyme ecosystem faces challenges with newer React versions.
npm install enzyme-adapter-utilsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how a custom Enzyme adapter, designed by a library developer, would extend `EnzymeAdapter` and utilize internal utilities like `RSTreeNode` and `syncWithReactDom` from `enzyme-adapter-utils`. It is not for end-users writing tests.
Refer to the Enzyme migration guide from v2 to v3. Ensure you are using `enzyme` v3.x and an `enzyme-adapter-react-*` package compatible with your React version (e.g., `enzyme-adapter-react-16` for React 16).
For React 17+ (especially React 18+), it is highly recommended to migrate from Enzyme to React Testing Library, which is officially supported by the React team and focuses on user-centric testing.
Application developers should only interact with the public API of the main `enzyme` package and a specific `enzyme-adapter-react-*` package. Custom adapter development is a niche use case.
Wrap any code that triggers state updates or effects outside of Enzyme's automatic `act` wrapping with `ReactTestUtils.act(() => { /* ... */ });` or similar `act` utilities relevant to your React version and testing setup.Install the correct `enzyme-adapter-react-*` package for your React version (e.g., `npm i --save-dev enzyme-adapter-react-16`) and configure Enzyme in your test setup file: `import Enzyme from 'enzyme'; import Adapter from 'enzyme-adapter-react-16'; Enzyme.configure({ adapter: new Adapter() });`Ensure that your `react` and `react-dom` versions are compatible with the specific `enzyme-adapter-react-*` package you are using. If conflicts persist, try `npm install --force` or `npm install --legacy-peer-deps` (use with caution as it can lead to broken dependencies) or downgrade/upgrade React to match the adapter's requirements.
Verify that your custom adapter correctly extends `EnzymeAdapter` or reinstall the official `enzyme-adapter-react-*` package to ensure it's not corrupted. Ensure no conflicting versions of `enzyme-adapter-utils` are present.