angular - 在 @ViewChild 变量中使用 spyOn 时出错
问题描述
我有一个使用的组件
@ViewChild(NgbDropdown) public dropdown: NgbDropdown;
this.dropdown.isOpen();
在我的规范文件中,我需要将isOpen()
结果模拟为 true,但我似乎无法监视它。
收到此错误:
Error: <spyOn> : could not find an object to spy upon for isOpen()
Usage: spyOn(<object>, <methodName>)
提前致谢!
解决方案
这与 linter 有关
这就是它应该被嘲笑的方式
component.dropdown = jasmine.createSpyObj(['isOpen']);
(component.dropdown as SpyObj<NgbDropdown>).isOpen.and.returnValue(true);
谢谢!
推荐阅读
- c# - ML.NET 如何检测 C# 中方法链的结尾?
- java - Elasticsearch Java:无法为对象堆错误保留足够的空间
- typescript - 当与字符串原始类型联合时,使打字稿显示字符串文字的类型提示
- python - 检查列表中是否只有一种元素是连续的?
- python-3.x - 如何将多个 Lambda 函数从 python 2.7 更新到 3.6
- python - 我的第一个 python 程序!所得税计算器
- node.js - 当我将会话存储到 redis 时无法获取 cookie
- angular - 使用 Nestjs 进行社交登录。REST API 的问题
- c++ - 为什么“static”关键字解决了嵌套类中非常量类型的无效初始化但仍然输出错误?
- powerbi - 如何将 o365 安全与合规中心数据导入 PowerBI