问题描述
我正在为我的项目使用graphQL挂钩,我在测试中遇到问题,它会显示此错误:
TypeError: Cannot read property 'useGETForQueries' of undefined
const [searchManual,{ loading: searchLoading,data,error }] = useManualQuery(SEARCH_QUERY);
默认情况下,useGETForQuereies
是false
,但不确定为什么运行测试时会出现此错误。项目运行正常,这只是测试用例。我已在GraphQlClient
const gqlAxios = axios.create()
gqlAxios.interceptors.response.use(
function (response) {
if(response.status === 401 || response.status === 403 )
window.location.href = config.api.LOGIN_URL;
return response;
},function (error) {
console.log("responseError",error);
return Promise.reject(error);
}
)
gqlAxios.interceptors.request.use(
function (config) {
config = {
...config,headers: {
...config.headers,'session': getCookieValue()
}
}
return config;
}
)
const fixed = config.api.APP_GQL_HOST;
const url = fixed + 'graphql';
export const client = new GraphQLClient({ url,fetch: buildAxiosFetch(gqlAxios),useGETForQueries: false });
client
常量将导出到index.js
,并用作ClientContext.Provider
中的值。
const Wrapped = (
<ClientContext.Provider value={client}>
<App />
</ClientContext.Provider>
)
ReactDOM.render(
Wrapped,document.getElementById('root')
);
console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
Error: Uncaught [TypeError: Cannot read property 'useGETForQueries' of undefined]
it('Expect component in the document',() => {
const { getByTestId } = render(<Search />);
const component = getByTestId("test");
expect(component).toBeInTheDocument();
});
是否需要添加其他配置?我想使用msw
(模拟服务工作程序),但是我陷入了这个错误,无法前进。有没有人遇到graphql hooks
的错误?另外,您对该图书馆有什么经验?优点是重量轻,但在测试时似乎并不友好。与阿波罗的任何比较。感谢您对这个问题的见识。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)