javascript - 更改 QraphQL 端点的 cypress 测试中的路由数据
问题描述
我有一个使用 QraphQL 的 Angular 应用程序。我在 cypress 中编写了一个测试,如下所示:
it('should do something', () => {
cy.server();
cy.route('POST', '/graphql', 'fixture:data1.json');
// data is loaded from the endpoint to populate the page
cy.visit('http://localhost:3000/#/something/somethingElse');
// when the button is clicked, the same endpoint is called again,
// but now I need it to deliver some other data.
cy.get('button')
.click();
});
任何人都可以为我提供一种设置方法吗?提前致谢
解决方案
也许你可以使用easygraphql来解决这个挑战!!有多个包可以使用:
easygraphql-now:您可以在您的脚本上创建一个脚本,该脚本
package.json
将"easygraphql-now schema.gql --graphiql --local -p=7000"
在您传递架构路由、本地和 graphiql 标志以及端口的位置运行......所以当您运行它时;它将创建传递模式的模拟服务器,因此您的 Angular 应用程序将向服务器发出请求,该服务器将响应您的查询的模拟。这是一个有用的帖子。easygraphql-mock:如果你想返回一个完整的类型的模拟,你可以使用这个包,有了这个,你不必为每种类型创建夹具。
easygraphql-tester:它类似于easygraphql-mock但不同之处在于您可以返回查询的模拟,请查看文档
如果您决定使用easygraphql来解决这个问题,请随时在 repo 上创建示例,这里有一个问题,使用 Cypress 创建示例
推荐阅读
- sql-server - SQL Server - 唯一索引与唯一约束 - Re。重复值
- mysql - 如何用外键做到这一点?
- javascript - 动态验证所有无线电输入均已检查
- wpf - 在 Silverlight 中将 Observable 集合列表绑定到动态创建的 ComboBox
- javascript - 如何正确配置 babel 以使用 lodash-es?
- python - Gunicorn ModuleNotFoundError
- opengl-es - Android OpenGL ES 旋转屏幕
- java - 在 spring-data-mongodb 中检索地图 mongo 集合
- python - 高效访问 mxnet 中的任意 NDArray 批次
- python - 从python中的随机列表中选择时出错