cypress 和 react-apollo 之间的兼容性 [英] Compatibility between cypress and react-apollo

查看:32
本文介绍了cypress 和 react-apollo 之间的兼容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用

但 Cypress 似乎无法捕获任何东西,除了 XHR 请求.

那么我能做些什么来解决这个问题呢?赛普拉斯有没有办法捕获获取"请求?react-apollo 有没有办法使用xhr"而不是fetch"?

解决方案

Cypress 现在正式支持使用 GQL:使用 GraphQL.

我建议您详细阅读他们的文档,但这里的 TLDR 非常粗糙,风险自负:

cy.intercept('your-url-here/graphql', (req) => {const { body } = req;if (body.hasOwnProperty('your-operationName-here')) {//对请求做一些事情,比如:req.reply('你的模拟在这里');}});

I am using react-apollo to make GraphQL queries, and I am using Cypress for testing.

The problem is that these 2 dont seem to play well along. Apollo seems to be making all its requests through the Fetch API.

But Cypress seems like it is not able to capture anything, except XHR requests.

So what could I do to solve this problem? Is there a way for Cypress to capture "fetch" requests? Is there a way for react-apollo to use "xhr" instead of "fetch"?

解决方案

Cypress now officially supports working with GQL: Working with GraphQL.

I recommend reading their documentation in detail, but at your own risk here is a VERY crude TLDR:

cy.intercept('your-url-here/graphql', (req) => {
    const { body } = req;
    if (body.hasOwnProperty('your-operationName-here')) {
        // do something with the request, like:
        req.reply('your-mock-here');
    }
  });

这篇关于cypress 和 react-apollo 之间的兼容性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆