赛普拉斯-使用route(options)存根无效 [英] Cypress - stubbing using route(options) isn't work

查看:55
本文介绍了赛普拉斯-使用route(options)存根无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to simulate bad request by returning status code = 400.

我遵循了文档,发现我需要使用带有选项的路由功能:

I followed the documentation and found that I need to use the route function with an options:

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

这两个都不起作用-运行Cypress Test Runner-不会捕获请求,并且该请求是针对真实服务器的.请帮忙.谢谢!

Both of those didn't work - running the Cypress Test Runner - the request isn't captured and the request is against the real server. Please help. Thanks!

推荐答案

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

In case someone will come across this issue, you need to pass response as one of the parameters, like this:

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

这篇关于赛普拉斯-使用route(options)存根无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆