使用 sinon 模拟 window.location.reload
我正在使用 sinon 编写一段使用 window.location.reload();
执行重新加载的 Vue 代码测试。
代码工作正常,但测试失败并出现错误 错误:未实现:导航(哈希更改除外)
如果我删除该行代码,测试不会崩溃。
我怎样才能编写一个通过该行代码正确运行的 sinon 测试? 我不确定是否需要保留该行,尽管我不确定如何为财产做到这一点。
有什么想法吗?
I'm writting tests with sinon for a section of Vue code that performs a reload with window.location.reload();
.
The code works correctly, but the test is failing with an error Error: Not implemented: navigation (except hash changes)
If I delete that line of code, the tests don't crash.
How can I write a sinon test that runs correctly through that line of code?
I'm not sure if I need to stub that line, although I'm not sure how could I do it for a property.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑
onbeforeunload
,它会引发错误并阻止实际的页面重新加载,而assert.throws
会捕获错误。像这样的事情:Consider
onbeforeunload
which throws an error and prevents an actual page reloading, andassert.throws
catching the error. Something like this: