【问题标题】:Changing data for route in cypress test for QraphQL endpoint在 GraphQL 端点的 cypress 测试中更改路由数据
【发布时间】:2019-05-03 09:08:34
【问题描述】:

我有一个使用 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();
});

谁能为我提供一种设置方法? 提前致谢

【问题讨论】:

    标签: javascript testing graphql integration-testing cypress


    【解决方案1】:

    也许你可以使用easygraphql 来解决这个挑战!!有多个包可以使用:

    1. easygraphql-now:您可以在package.json 上创建一个脚本,该脚本将运行"easygraphql-now schema.gql --graphiql --local -p=7000",您可以在其中传递架构路由、本地和graphiql 标志以及端口……所以当您运行它时;它将创建传递模式的模拟服务器,因此您的 Angular 应用程序将向服务器发出请求,该服务器将响应您的查询的模拟。这是一个很有用的post

    2. easygraphql-mock:如果你想返回一个完整的类型的mock,你可以使用这个包,这样你就不必为每个类型创建fixture。

      李>
    3. easygraphql-tester:类似于easygraphql-mock,不同的是可以返回查询的mock,查看docs

    如果您决定使用easygraphql 来解决此问题,请随时在 repo 上创建示例,here 使用 Cypress 创建示例存在问题

    【讨论】:

      猜你喜欢
      • 2018-09-04
      • 2016-09-01
      • 2021-12-02
      • 2021-08-25
      • 2023-03-26
      • 2018-04-01
      • 2021-04-29
      • 2021-11-05
      • 1970-01-01
      相关资源
      最近更新 更多