我正在编写一个使用 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');
});
Run Code Online (Sandbox Code Playgroud)
不幸的是,我从 graphql 中得到一个错误,抱怨它id是一个Int而不是ObjectId. 我错过了什么吗?
问题是fetch在 Cypress 中还没有实现存根请求(这是 Vue Apollo 正在使用的)。我结束了以下这些说明:
github/fetchcypress/support/index.js:.
Cypress.on('window:before:load', win => {
win.fetch = null;
win.Blob = null;
});
Run Code Online (Sandbox Code Playgroud)
现在它起作用了!
| 归档时间: |
|
| 查看次数: |
2028 次 |
| 最近记录: |