酶支持React React 18吗?
最近,React 18已发布,我将项目升级到18。我注意到Jest和Zhyme撰写的所有单元测试都失败了。我已经将酶的安装量用作组件的包装器,并注意到以下错误:
TypeError: Cannot read property 'child' of undefined
我还试图检查它是否支持React 18,但找不到任何合适的链接。
有人对此有任何想法吗?还是在这种情况下可以遵循任何解决方法?
Recently, React 18 has released and I have upgraded my project to 18. I noticed that all of my unit tests that were written by Jest and Enzyme are failing. I have used mount from Enzyme as a wrapper of my component and noticed the following error:
TypeError: Cannot read property 'child' of undefined
I also tried to check if it has support for React 18 yet but couldn't find any suitable link about that.
Does anybody have any thoughts about that? Or are there any workarounds that can be followed in that case?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
酶已经死亡。 (不会有React 18支持)
您可以阅读下面的文章以获取更多信息,但简而言之:
React 18中的API变化意味着释放A React 18酶适配器将是不可能的
,
从酶支持文章中迁移可用,可用 我建议您只是开始新鲜,忘记酶曾经存在。 rtl绝不是酶的置换式替换,因此拥有完全新鲜的心态将有助于您充分利用它。
我应该怎么办?
答案一如既往地取决于。毕竟,您不必升级反应。
这是我要做的:
18 酶-apapter-reactct-17 , react-pdf , react-calendar 和 react-date-date-picker :
https://dev.to/wojtekmaj/enzyme-is-dead-now - what-ekl
Enzyme is dead. (There will be no React 18 support)
you can read the article below for more info but in short:
the API changes in React 18 meant that releasing a React 18 Enzyme adapter will not be possible
A bit of personal advice
While Migrate from Enzyme support article is available, I suggest you to just start fresh, forgetting that Enzyme has ever existed. RTL is by no means an Enzyme drop-in replacement, so having a completely fresh mindset will help you getting the most of it.
What should I do?
The answer is, as always, it depends. You don't have to upgrade React, after all.
Here's what I would do:
Link of complete article by Wojciech Maj, maintainer of @wojtekmaj/enzyme-adapter-react-17, React-PDF, React-Calendar, and React-Date-Picker:
https://dev.to/wojtekmaj/enzyme-is-dead-now-what-ekl
@wojtekmaj/酶-apapter-react-17(反应的非官方适配器17)的维护者警告说酶已经死亡。 React 18的支持将需要完全重写它。这是链接 https://dev.to/dev.to/wojtekmaj/enzyme-iseme-iszyme-is-seme-iseme-ise-enzyme-is -Ead-now-what-ekl
他建议搬到RTL或坚持使用React 16-17
The maintainer of @wojtekmaj/enzyme-adapter-react-17 (unofficial adapter for React 17) warns that enzyme is dead. The support of React 18 would require a complete rewrite of it. Here is the link https://dev.to/wojtekmaj/enzyme-is-dead-now-what-ekl
He suggests to either move to RTL or stick with React 16-17
React 18以
React 18 was released in March 2022. Enzyme's last commit is from September 2021. It seems fair to assume that Enzyme has not yet been updated to guarantee compatibility with React 18.
当前没有官方反应18支持: https://github.com/github.com/enzymejs/enzymejs/enzymejs/enzyme/sissues/sissues/sissues/issues /2524
但是,您可以尝试使用单独的配置进行测试,并使用React 17: https://github.com/enzymejs/enzyme/issues/2524#issuecomment-116246491
There currently is no official React 18 support: https://github.com/enzymejs/enzyme/issues/2524
However you can try to run your tests with a separate config and with react 17: https://github.com/enzymejs/enzyme/issues/2524#issuecomment-1116246491
不是官方的,而是值得尝试作为短期解决方案,直到您可以迁移到rtl:
https://www.npmjs.com/package/@cfaester/enzyme-adapter-reakct-18
Not official, but worth trying as a short-term solution until you can migrate to something like RTL:
https://www.npmjs.com/package/@cfaester/enzyme-adapter-react-18