问题
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');
  });
Unfortunately, I get an error from graphql complaining that id is an Int instead of an ObjectId. Am I missing something?
回答1:
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:
- Install github/fetch
- Add this to cypress/support/index.js:
.
Cypress.on('window:before:load', win => {
  win.fetch = null;
  win.Blob = null;
});
Now it works!
来源:https://stackoverflow.com/questions/49079005/how-to-stub-a-call-to-graphql-using-cypress