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 (将#修改为@)