本文介绍了如何使用赛普拉斯存根对graphql的调用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个使用vue-apollo与graphql进行交互的Vue应用。我想知道是否可以对graphql请求进行存根。我认为这应该可行:

I'm writing a Vue app that uses vue-apollo to interact with graphql. I'm wondering if it's possible to stub the graphql requests. I thought this should work:

  it('should access a story', function() {
    cy.server();
    cy.route('http://localhost:3002/graphql', {
      data: {
        Story: { id: 2, title: 'story title', content: 'story content' }
      }
    });

    cy.visit('/stories/2');
  });

不幸的是,我从graphql收到一个错误,抱怨 id 是 Int 而不是 ObjectId 。我丢失了什么吗?

Unfortunately, I get an error from graphql complaining that id is an Int instead of an ObjectId. Am I missing something?

推荐答案

问题是存根获取请求尚未在赛普拉斯中实现(Vue Apollo正在使用)。我最终遵循了说明:

The problem was that stubbing fetch requests isn't yet implemented in Cypress (which is what Vue Apollo is using). I ended up following these instructions:


  • 安装

  • 将此添加到 cypress / support / index.js

  • Install github/fetch
  • Add this to cypress/support/index.js:

Cypress.on('window:before:load', win => {
  win.fetch = null;
  win.Blob = null;
});

现在可以了!

这篇关于如何使用赛普拉斯存根对graphql的调用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:56