React Testing库给出了ReactDom的控制台错误。
在更新了React 18或从创建新的React 18应用程序后,当我运行
YARN TEST
命令时,它给出了 Console.error
作为渲染
在任何测试中使用的方法的警告:
Console.Error
警告:ReactDom.Render不再支持React 18中的支持。改用Croteroot。在您切换到新的API之前,您的应用程序将表现得好像正在运行17。 ://reactjs.org/link/switch-to-createroot
作为React测试库似乎不支持React 18方法论。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
解决react测试库错误:
“ReactDOM.render在React 18中不再支持,请更新react测试库的版本。”
在项目的根目录中打开终端并运行以下命令:
确保更新您正在使用的所有反应测试库包的版本。
您的index.js 文件应使用新的createRoot API 来呈现您的应用程序。
index.js
现在您应该能够开始测试而不会出现错误。
应用程序.test.js
To solve the react testing library error:
"ReactDOM.render is no longer supported in React 18, update the version of the react testing library."
Open your terminal in the root directory of your project and run the following commands:
Make sure to update the versions of all react testing library packages you are using.
Your index.js file should use the new createRoot API to render your application.
index.js
Now you should be able to start your tests without getting the error.
App.test.js
卸载
@testing-library/react-hook
并从@testing-library/react
导入renderHook
请参阅此处 https://github.com/testing-library/react-hooks-testing-library/issues/826#issuecomment-1100650242
uninstall
@testing-library/react-hook
and importrenderHook
from@testing-library/react
see here https://github.com/testing-library/react-hooks-testing-library/issues/826#issuecomment-1100650242
有关所有库的快速更新,您可以使用下一个命令:
npm install -g npm-check-updates
NCU -U
NPM Update
For quick update of all the libraries you can use next commands:
npm install -g npm-check-updates
ncu -u
npm update