问题描述
我正在尝试为我使用 apollo+graphql 的 TS+NextJS 应用程序测试一些带有玩笑的打字稿代码。 Unfornautley,我收到错误
TypeError: React.createContext is not a function
来自以下节点模块:
getApolloContext (node_modules/@apollo/client/react/context/ApolloContext.js:7:25)
当我在 Stack Overflow 上的其他问题上查看此错误时,它说 react 版本已过时,但我的 package.json 中的 react 版本是
"react": "^17.0.1",
所以我不确定是什么导致了这个问题。似乎由于某种原因,类型检查失败,或者在该节点模块中使用了旧版本的 react 而不是项目范围的,这似乎不正确。
到目前为止我尝试过的是:
更新我的 react 和 react-dom 节点模块(什么都不做)
非常执着于除此之外要做的事情。
test.tsx
import * as React from 'react';
import { render } from '@testing-library/react'
import DonePage from '../pages/done'
describe('Pages',() => {
describe('Index',() => {
it('Pages render',function testCases() {
render(<DonePage apolloClient={{}} apolloState={{}}/>)
})
})
})
export {}
page.tsx
import * as React from 'react';
import { withApollo } from 'apollo'
{...}
const DonePage: NextPage<{}> = () => {
return (
<>
{...}
</>
)
}
export default withApollo(DonePage,{ ssr: false })
其中 withApollo
是 https://github.com/apollographql/apollo-client/issues/5089 中的代码
我正在使用 jest --runInBand
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)