我正在使用
但是赛普拉斯似乎无法捕获任何东西,除了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
更多推荐
柏树与阿波罗之间的相容性
发布评论