如何使用Cypress.io断言已开始下载文件而没有实际下载? [英] How can I use Cypress.io to assert that a file download has been initiated without actually downloading?

查看:191
本文介绍了如何使用Cypress.io断言已开始下载文件而没有实际下载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过设置

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.

推荐答案

您本质上想要做的是对 使用 cy.stub() 测试您的应用程序是否已调用 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答案中,有一个很好的答案: https://stackoverflow.com/a/36678937/5878476

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断言已开始下载文件而没有实际下载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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