Cypress 7中无法覆盖Intercept拦截器的问题排查
Cypress 7版本中无法覆盖Intercept拦截器的问题
我正在从Cypress 5版本升级到7版本,目前卡在拦截器覆盖的问题上——尝试覆盖beforeEach中定义的Intercept拦截器始终失败。
查资料时发现信息矛盾:有的内容提到设置同路径但不同别名的拦截器时,只有第一个会触发;但另一些内容表示,相似路径不同别名的拦截器都会触发。
我的代码如下:
... describe("Loading Inventory", () => { beforeEach(() => { cy.intercept("GET", "/ui_connect/inventory/**", { fixture: "operator/file.json", statusCode: 200, }).as("checkInventoryRequest"); }); it("My test", () => { cy.intercept("GET", "/ui_connect/inventory/**", { body: {}, statusCode: 500, }).as("checkInventoryRequestWithError"); cy.get("[data-test=inventory-button]").click(); // 触发请求 cy.wait("@checkInventoryRequestWithError").then(() => { cy.get(".e-alert-dialog") .contains("Inventory Generation Error") .should("be.visible"); }); }); }); });
我想要覆盖beforeEach里定义的拦截器,但请求始终返回200状态码和fixture中的内容,哪怕把两个拦截器设为相同别名也没用。
根据Cypress官方文档,请求阶段应该采用最后定义的拦截器并终止处理,但实际情况并非如此。请问我的代码哪里有问题?
内容的提问来源于stack exchange,提问作者Ricardo
相关产品推荐
相关产品推荐

