柏树不匹配存根路由

问题描述 投票:1回答:1

我正在我的应用程序代码中进行此操作:

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的日志中,我看到了请求,但说不匹配:

enter image description here

在Chrome的devtools中,我看到了,但是我得到的响应是来自服务器的真实响应:

enter image description here

enter image description here

任何想法?

testing cypress e2e-testing
1个回答
0
投票

如docs here中所述,使用复杂的字符串时,URL必须完全匹配。我建议使用glob模式选项:

it.only("test", () => {
  cy.server();
  cy.route("GET", "**/labels", [
    { text: "foo" }
  ]);
});
© www.soinside.com 2019 - 2024. All rights reserved.