哪种酶适配器适用于 React 17? [英] Which Enzyme adapter works with React 17?

查看:31
本文介绍了哪种酶适配器适用于 React 17?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 React 应用程序,我想开始使用 Enzyme 编写单元测试.Enzyme 的文档讨论了高达 16 的 React 版本.

I have a React app, and I want to start writing unit tests with Enzyme. Enzyme's documentation discusses versions of React up to 16.

src/setupTests.js 我目前有

import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

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

但我的应用使用 React 17.0.1 版.React 17 有什么酶适配器?

But my app uses React version 17.0.1. What enzyme adapter is there for React 17?

推荐答案

React 17 有什么酶适配器?

如果你有 React 版本 17,你可以使用这个 用于酶的 React 17 的非官方适配器.

If you have React version 17, you can use this unofficial adapter for React 17 for enzyme.

// src/setupTests.js
import { configure } from 'enzyme';
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';

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

有关非官方适配器的更多信息,请参阅此GitHub 问题.

See this GitHub issue for more information on the unofficial adapter.

这篇关于哪种酶适配器适用于 React 17?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆