在 GraphQL 端点的赛普拉斯测试中更改路由数据

Changing data for route in cypress test for QraphQL endpoint

我有一个使用 GraphQL 的 Angular 应用程序。 我用柏树写了一个测试,看起来像这样:

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来解决这个挑战!!有多个包可以使用:

  1. easygraphql-now: you can create a script on your package.json that will run "easygraphql-now schema.gql --graphiql --local -p=7000" where you pass the schema route, local and graphiql flag, and the port... so when you run it; it will create a mocked server of the passed schema, so your Angular application will make request to a server that will respond a mock of your query. Here is a post 很有用。

  2. easygraphql-mock:如果你想return一个完整的模拟类型,你可以使用这个包,有了这个,你不必创建固定装置对于每种类型。

  3. easygraphql-tester: 它类似于 easygraphql-mock 但不同的是你可以 return 模拟查询,检查 文档

如果您决定使用 easygraphql 来解决这个问题,请随时在 repo 上创建示例,此处 有一个使用 Cypress 创建示例的问题