Jasmine测试观察者是否's的下一个已被调用



我有一个行为主题:

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(...);

最新更新