How can I use Cypress.io to assert that a file download has been initiated without actually downloading?

僤鯓⒐⒋嵵緔 提交于 2019-12-10 15:35:21

问题


The download is initiated by setting

location.href = [some url to an image]

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.


回答1:


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.

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



来源:https://stackoverflow.com/questions/47930881/how-can-i-use-cypress-io-to-assert-that-a-file-download-has-been-initiated-witho

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!