在react项目中跑jest的测试报错:Element type is invalid: expected
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过jest.mock解决了