问题描述
我有一个使用QraphQL的Angular应用程序。
我用柏树编写了一个测试,看起来像这样:
I have an Angular application using QraphQL.I write a test in cypress, looking like this:
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();
});
有人可以给我提供一种设置方法吗?
预先感谢
Can anyone provide me with a way to set this up?Thanks in advance
推荐答案
也许您可以使用来解决这个挑战!可以使用多个软件包:
Maybe you can use easygraphql to solve this challenge!! There are multiple packages that can be used:
-
:您可以在
package.json
上创建一个脚本,该脚本将运行easygraphql-now schema.gql --graphiql --local -p = 7000
在其中传递模式路由,local和graphiql标志以及端口...因此在运行它时;它将为传递的架构创建一个模拟服务器,因此您的Angular应用程序将向服务器发出请求,该服务器将响应您的查询模拟。这是一个:如果您想返回该类型的完整模拟,则可以使用此包,并且不必为此创建每种灯具。easygraphql-mock: if you want to return a complete mock of the type, you can use this package, and with this, you don't have to create fixtures for each type.
:相似到,但是区别在于您可以返回查询的模拟,检查
easygraphql-tester: It's similar to easygraphql-mock but with the difference that you can return the mock of the query, check the docs
如果您决定使用来解决此问题,随时在仓库上创建示例,出现问题使用赛普拉斯创建示例
If you decide to use easygraphql to solve this, feel free to create the example on the repo, there is an issue here to create an example using Cypress
这篇关于更改赛普拉斯QraphQL端点测试中的路由数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!