【问题标题】:Check calling of endpoint in Cypress检查赛普拉斯端点的调用
【发布时间】:2020-08-24 10:48:36
【问题描述】:

我有以下代码,我想检查/account/logout服务是否被调用,如何实现?

it('should log out', () => {
  // It will be good to check if application returned
  // to login page and if /account/logout endpoint has been called.
  cy.get('[alt="user_avatar"]')
    .should('be.visible')
    .click()
    .get('[data-cy=cy-btn-signout]')
    .click();

  cy.wait(500)
  cy.url().should('include', '/login');

  cy.pause();
});

【问题讨论】:

  • 你为什么要检查那个?您的用户并不关心调用了哪些端点,如果可以避免的话,我不会将 E2E 测试与 API 耦合。

标签: typescript cypress


【解决方案1】:

我想查看/account/logout服务是否被调用,如何实现?

假设它是一个post call:

  cy.server();
  cy.route('POST', '/account/logout').as('logout');
  cy.wait('@logout');

更多

【讨论】:

    猜你喜欢
    • 2018-10-03
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-11
    • 2023-02-14
    相关资源
    最近更新 更多