【问题标题】:Cypress not matching stubbed route赛普拉斯不匹配存根路由
【发布时间】:2020-04-07 10:33:18
【问题描述】:

我在我的应用代码中这样做:

const xhr = new XMLHttpRequest();
xhr.open("GET", "https://api.gizconnection.com/labels", true);
xhr.setRequestHeader("Authorization", "Bearer " + authService.getToken());
xhr.send(null);

在我的测试中我有:

it.only("test", () => {
  cy.server();
  cy.route("GET", "https://api.gizconnection.com/labels", [
    { text: "foo" }
  ]);
});

但不匹配,我快疯了。

在 CY 的日志中,我看到了请求,但说它不匹配:

在 Chrome 的开发工具中,我看到了它,但我得到的响应是来自服务器的真实响应:

有什么想法吗?

【问题讨论】:

    标签: testing cypress e2e-testing


    【解决方案1】:

    如文档here 中所述,使用可能很棘手的字符串时,url 必须完全匹配。我建议使用 glob 模式选项:

    it.only("test", () => {
      cy.server();
      cy.route("GET", "**/labels", [
        { text: "foo" }
      ]);
    });
    

    【讨论】:

    • 我的网址一模一样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多