在react项目中跑jest的测试报错:Element type is invalid: expected

发布于 2022-09-11 22:03:16 字数 2801 浏览 15 评论 0

react项目在浏览器跑没问题,但是跑jest单元测试报错

Test suite failed to run

Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.


  
  at invariant (node_modules/react-dom/cjs/react-dom.development.js:55:15)
  at createFiberFromTypeAndProps (node_modules/react-dom/cjs/react-dom.development.js:10100:11)
  at createFiberFromElement (node_modules/react-dom/cjs/react-dom.development.js:10121:15)
  at reconcileSingleElement (node_modules/react-dom/cjs/react-dom.development.js:12392:23)
  at reconcileChildFibers (node_modules/react-dom/cjs/react-dom.development.js:12449:35)      at reconcileChildren (node_modules/react-dom/cjs/react-dom.development.js:14069:28)
  at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:14723:5)
  at beginWork (node_modules/react-dom/cjs/react-dom.development.js:15203:16)
  at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:18789:12)
  at workLoop (node_modules/react-dom/cjs/react-dom.development.js:18829:24)
  at renderRoot (node_modules/react-dom/cjs/react-dom.development.js:18912:7)
  at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:19809:7)
  at performWork (node_modules/react-dom/cjs/react-dom.development.js:19721:7)
  at performSyncWork (node_modules/react-dom/cjs/react-dom.development.js:19695:3)
  at requestWork (node_modules/react-dom/cjs/react-dom.development.js:19564:5)
  at scheduleWork (node_modules/react-dom/cjs/react-dom.development.js:19373:5)
  at scheduleRootUpdate (node_modules/react-dom/cjs/react-dom.development.js:20041:3)
  at updateContainerAtExpirationTime (node_modules/react-dom/cjs/react-dom.development.js:20069:10)
  at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:20126:10)
  at ReactRoot.Object.<anonymous>.ReactRoot.render (node_modules/react-dom/cjs/react-dom.development.js:20422:3)
  at node_modules/react-dom/cjs/react-dom.development.js:20559:14
  at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:19924:10)
  at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:20555:5)
  at Object.render (node_modules/react-dom/cjs/react-dom.development.js:20624:12)
  at render (node_modules/dva/lib/index.js:113:12)
  at Object.start (node_modules/dva/lib/index.js:81:7)
  at Object.<anonymous> (src/index.js:189:5)
  at Object.<anonymous> (src/utils/request.js:1727:33)
  at Object.<anonymous> (src/utils/utils.js:2582:35)
  at Object.<anonymous> (src/utils/tests/utils.test.js:9:14)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

清旖 2022-09-18 22:03:16

通过jest.mock解决了

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