我正在我的应用程序代码中进行此操作:
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的devtools中,我看到了,但是我得到的响应是来自服务器的真实响应:
任何想法?
如docs here中所述,使用复杂的字符串时,URL必须完全匹配。我建议使用glob模式选项:
it.only("test", () => {
cy.server();
cy.route("GET", "**/labels", [
{ text: "foo" }
]);
});