我正在编写一个使用 vue-apollo 与 graphql 交互的 Vue 应用程序。我想知道是否可以存根 graphql 请求。我认为这应该有效:
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
is an Int
而不是ObjectId
。我错过了什么吗?
问题是存根fetch
requests 尚未在 Cypress 中实现(Vue Apollo 正在使用它)。我最终跟随these https://github.com/cypress-io/cypress/issues/95#issuecomment-347607198指示:
- Install github/fetch https://github.com/github/fetch
- 将其添加到
cypress/support/index.js
:
.
Cypress.on('window:before:load', win => {
win.fetch = null;
win.Blob = null;
});
现在可以了!
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)