问题描述
通过设置
location.href = [some url to an image]
我想尽可能断言,下载将成功完成,但实际上并未执行下载。可以假定该URL是正确的。
I want assert, as close as possible, that the download will succeed but without actually performing the download. That the URL is correct can be assumed.
推荐答案
您本质上想要做的是对 使用,但测试您的应用程序是否已调用 location.href
并声明传递给它的url
有点棘手,因为 href
是属性而不是函数。存根不能替换属性,只能替换功能。
What you essentially want to do is stub a call to location.href
using cy.stub()
, but testing that your application has called location.href
and asserting the url
passed to it is a bit tricky since href
is an attribute, not a function. Stubs cannot replace attributes, only functions.
这可以通过对应用程序代码进行一些重组来测试。在以下stackoverflow答案中,有一个很好的答案:
This is testable with some restructure of your application code. There is a great answer on how to do this in this stackoverflow answer: https://stackoverflow.com/a/36678937/5878476
这篇关于如何使用Cypress.io断言已开始下载文件而没有实际下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!