酶支持React React 18吗?

发布于 2025-01-24 22:38:29 字数 243 浏览 4 评论 0原文

最近,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

南渊 2025-01-31 22:38:29

酶已经死亡。 (不会有React 18支持)

您可以阅读下面的文章以获取更多信息,但简而言之:

React 18中的API变化意味着释放A React 18酶适配器将是不可能的


从酶支持文章中迁移可用,可用 我建议您只是开始新鲜,忘记酶曾经存在。 rtl绝不是酶的置换式替换,因此拥有完全新鲜的心态将有助于您充分利用它。


我应该怎么办?

答案一如既往地取决于。毕竟,您不必升级反应。

这是我要做的:

  1. 开始熟悉 react testing库(rtl ) ,一个正式推荐的React组件库。
  2. 制定一个仅使用RTL编写新测试的规则。
  3. 每当您需要触摸它们和/或他们正在测试的组件时,请考虑制定规则将测试重写为RTL。
  4. 在您指定的偿还技术债务的时间(您有指定的时间偿还技术债务的时间,对吗?…对吗?),将剩余的基于酶的测试重写为RTL。
  5. 准备就绪时,请从酶特定的位清理您的存储库,升级到React

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:

  1. Start familiarizing yourself with React Testing Library(RTL), an officially recommended library for React components.
  2. Make a rule to write new tests using RTL only.
  3. Consider making a rule to rewrite tests to RTL whenever you need to touch them and/or the component they are testing.
  4. In your designated time for repaying technical debt (you have designated time for repaying technical debt, right? …right?), rewrite your remaining Enzyme-based tests to RTL.
  5. Clean up your repo from Enzyme-specific bits
  6. When you're ready, upgrade to React 18.

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

墨小沫ゞ 2025-01-31 22:38:29

@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

最冷一天 2025-01-31 22:38:29

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.

习惯成性 2025-01-31 22:38:29

当前没有官方反应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

无力看清 2025-01-31 22:38:29

不是官方的,而是值得尝试作为短期解决方案,直到您可以迁移到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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文