微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

TypeError:React.createContext 不是 Apollo、GraphQL 和 Jest 的函数

如何解决TypeError:React.createContext 不是 Apollo、GraphQL 和 Jest 的函数

在 NextJS 应用程序中,我尝试使用 Jest 和 react-testing-library 包含单元测试

当我尝试使用 yarn test 进行测试时,出现以下错误

 console.error
Error: Uncaught [TypeError: React.createContext is not a function]
    at reportException (/home/admin-1/Documents/unit-test/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:62:24)

当前反应版本:

"react": "^17.0.2","react-dom": "^17.0.2",

当前的开发依赖:

"@babel/core": "^7.8.6","@babel/preset-env": "^7.8.6","@babel/preset-react": "^7.8.3","@testing-library/jest-dom": "^5.1.1","@testing-library/react": "^9.4.1","babel-jest": "^25.1.0","babel-plugin-styled-components": "^1.10.7","jest": "^25.1.0","jest-axe": "^3.3.0","prettier": "^2.2.1","react-test-renderer": "^16.13.0"

尝试: 更新我的 react 和 react-dom 节点模块(没有帮助)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。