1.0.1 • Published 2 years ago

@carlossloureiro/enzyme-adapter-react-18 v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm

@carlossloureiro/enzyme-adapter-react-18

A very and very unofficial adapter for React 18.0.0 only (used in lastest version of Expo) for Enzyme.

Should you count on it? Probably not. Can you use it as a reference for your own work? Perhaps.

Installation

yarn add --dev @carlossloureiro/enzyme-adapter-react-18

Configuration

You need to add it to Enzyme configuration. This is actually pretty easy. Just import it.

import Enzyme from 'enzyme';
import Adapter from '@carlossloureiro/enzyme-adapter-react-18';

Enzyme.configure({ adapter: new Adapter() });

I have personally had a few issues with tests using simulate on a mounted component. Specifically when using form libraries. To alleviate this, wrap your simulate calls in act(), like so:

await act(() => {
	mountWrapper.find('form').simulate('submit');
});

Motivation and thanks

At moment I'm using the latest version of expo (46.0.16) it requires the React 18.0.0 only and don't have support to React 18.2.0. So when I did yarn check I have the below error in console.

"@cfaester/enzyme-adapter-react-18#react-test-renderer#react@^18.2.0" doesn't satisfy found match of "react@18.0.0"

Due to the dependencies configurations of cfaester. Therefore in this repository I've fixed the React version to 18.0.0 to make it fully compatible with expo.

This couldn't be possible without the work of cfaester and his React 18 adapter. And the work of wojtekmaj, and his React 17 adapter. I think you should consider sponsoring him for their other projects as well.