柏树 - 使用路由(选项)的存根不起作用



我尝试通过返回状态代码 = 400 来模拟错误请求。

我按照文档进行操作,发现我需要将路由函数与选项一起使用:

cy.route({method : 'GET',url: 'users',status: 400});
cy.route({method : 'GET',url: '**/users/*',status: 400});

这两个都不起作用 - 运行Cypress 测试运行程序 - 请求未被捕获,并且请求针对真实服务器。 请帮忙。 谢谢!

如果有人遇到此问题,您需要将响应作为参数之一传递,如下所示:

cy.route({
method : 'GET',
url: 'users',
status: 400,
response: {}
});