柏树与阿波罗之间的相容性

编程入门 行业动态 更新时间:2024-10-14 10:43:47
本文介绍了柏树与阿波罗之间的相容性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用

但是赛普拉斯似乎无法捕获任何东西,除了XHR请求.

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

解决方案

一个简单的解决方法是使用 whatwg-fetch ,您可以通过npm将其添加为依赖项,然后...

cypress/support/fetch_to_xhr.js

function fetchToXhr(){让polyfill之前(()=> {cy.readFile('node_modules/whatwg-fetch/dist/fetch.umd.js').then((contents)=> polyfill = contents)Cypress.on('window:before:load',(win)=> {删除win.fetchwin.eval(polyfill)})})}fetchToXhr()

cypress/support/index.js

import"./fetch_to_xhr";

那次赛普拉斯将捕获graphql请求

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"?

解决方案

An easy workaround is to use whatwg-fetch, which you'd add as a dependency via npm and then...

cypress/support/fetch_to_xhr.js

function fetchToXhr() { let polyfill before(() => { cy.readFile('node_modules/whatwg-fetch/dist/fetch.umd.js') .then((contents) => polyfill = contents) Cypress.on('window:before:load', (win) => { delete win.fetch win.eval(polyfill) }) }) } fetchToXhr()

cypress/support/index.js

import "./fetch_to_xhr";

After that cypress will capture the graphql requests

更多推荐

柏树与阿波罗之间的相容性

本文发布于:2023-11-17 02:45:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1608522.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阿波罗   相容性   柏树

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!