angular - Jasmine 测试观察者的下一个是否被调用
问题描述
我有一个行为主题:
public dataObserver = new BehaviorSubject<any>(null);
当我在订阅块中收到数据时,我接下来会调用这个:
this.dataObserver.next(response);
我在编写单元测试用例以测试是否已调用 next 时遇到问题。请帮帮我。我试图在现有问题中查找,但没有找到任何问题。如果您有任何问题,请回复有关堆栈溢出的相关问题的链接。
解决方案
尝试做:
spyOn(component.dataObserver, 'next').and.callThrough(); // and.callThrough() is optional
// put it if you want next to be called with its actual implementation
....
expect(component.dataObserver.next).toHaveBeenCalled(); // you can also use .toHaveBeenCalledWith(...);
推荐阅读
- python - 如何按名称查找类方法,如表单 globals()?
- python - 向数据添加条件列
- windows - Windows 文件资源管理器的窗口标题中不包含应用程序名称
- python - VS 代码默认终端配置文件不适用于“在终端中运行 Python”按钮
- c# - 带有任务队列的 ASP.Net Core 后台服务,是否需要 Task.Delay?
- python - shutil.copyfile() 在目标文件路径上抛出 Errno 2 异常
- swift - 无法将从 Firebase 获取的数据添加到新数组
- sql - 根据值周围的范围更新行,而不更改最初不在范围内的行
- json - lua dkjson 从 json 数组中获取值
- vba - 以编程方式更改 Word 范围内的段落位置