如何使用 RSpec 测试 javascript 重定向? [英] How to test a javascript redirect with RSpec?

查看:39
本文介绍了如何使用 RSpec 测试 javascript 重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 xhr :post 与控制器交互,我期待重定向.在 js.erb 我有 window.location.href = address .手动测试,浏览器正确重定向.我如何使用 RSpec 测试它?response.should redirect_to 失败

I am using a xhr :post to interact with a controller, and I am expecting a redirect. In the js.erb i have window.location.href = address . Testing it manually, the browser gets redirected properly. How can i test it using RSpec? response.should redirect_to fails

推荐答案

我通过检查 js.erb 生成的响应正文解决了这个特定问题

I solved this particular problem inspecting the response body generated by the js.erb

response.body.should include("window.location.href")

因为感觉不对,只要有人点赞,我就接受我自己的回答.

Because it didn't feel right, I will accept my own asnwer as long as it gets upvoted.

这篇关于如何使用 RSpec 测试 javascript 重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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