Coder Social home page Coder Social logo

enzyme-adapter-react-18's Introduction

npm

@cfaester/enzyme-adapter-react-18

A very unofficial adapter for React 18 for Enzyme.

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

Installation

npm install --save-dev @cfaester/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 '@cfaester/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

This is not the best code I've ever written, but sometimes ripping out 900 tests, or going through hoops by running some tests under React 17 (can you really trust that anyway?), is just not feasible if you want the cool suspense features in, or dependencies depending on React 18.

This package can serve as a halfway stop towards migrating your tests to a newer framework like @testing-library/react, or to keep some of your shallow tests working.

I don't have much plan of spending a lot of time maintaining this package. But after some deliberation, I'd rather open source it, than sit on it. If nothing else, it can serve as a reference point for your own implementation.

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

enzyme-adapter-react-18's People

Contributors

cfaester avatar danguilherme avatar sienic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.