Karma单元测试reload异常处理
业务逻辑中存在
window.location.reload();
运行测试用例,会出现
的错误,导致测试用例无法完整进行。
可以使用sinon来解决这个问题
window.onbeforeunload = sinon.spy();
但是如果,你需要在一个模块的测试用例跑完之后,刷新页面进行下一个测试用例,就不用使用这种方法,这时需要屏蔽代码中的刷新页面逻辑。参考官方文档
4. For all other cases, the Swiss army knife /* istanbul ignore next */ may be used which skips the "next thing" in the source code 5. The "next" thing may be, among other things: A JS statement (including assignments, ifs, loops, switches, functions) in which case all of the statement is ignored for all forms of coverage. A switch case statement, in which case the particular case is ignored for branch coverage and its contents ignored for all forms A conditional inside a ternary expression in which case the branch is ignored A part of a logical expression in which case that part of the expression is ignored for branch coverage
那么直接用
/* istanbul ignore next */
window.location.reload();
进行屏蔽,发现并不能解决问题。仔细读文档,(including assignments, ifs, loops, switches, functions) ,只能屏蔽赋值、ifs、循环、开关、函数。所以封装一个函数
/* istanbul ignore next */
export const locationReload = () => {
/* istanbul ignore next */
window.location.reload();
};
这样子就可以屏蔽刷新页面
相关文章
- 在 Go 里用 CGO?这 7 个问题你要关注!
- 9款优秀的去中心化通讯软件 Matrix 的客户端
- 求职数据分析,项目经验该怎么写
- 在OKR中,我看到了数据驱动业务的未来
- 火山引擎云原生大数据在金融行业的实践
- OpenHarmony富设备移植指南(二)—从postmarketOS获取移植资源
- 《数据成熟度指数》报告:64%的企业领袖认为大多数员工“不懂数据”
- OpenHarmony 小型系统兼容性测试指南
- 肯睿中国(Cloudera):2023年企业数字战略三大趋势预测
- 适用于 Linux 的十大命令行游戏
- GNOME 截图工具的新旧截图方式
- System76 即将推出的 COSMIC 桌面正在酝酿大变化
- 2GB 内存 8GB 存储即可流畅运行,Windows 11 极致精简版系统 Tiny11 发布
- 迎接 ecode:一个即将推出的具有全新图形用户界面框架的现代、轻量级代码编辑器
- loongarch架构介绍(三)—地址翻译
- Go 语言怎么解决编译器错误“err is shadowed during return”?
- 敏捷:可能被开发人员遗忘的部分
- Denodo预测2023年数据管理和分析的未来
- 利用数据推动可持续发展
- 在 Vue3 中实现 React 原生 Hooks(useState、useEffect),深入理解 React Hooks 的