角度2+中可观察到的单元测试

问题描述 投票:0回答:1

如何编写返回可观察函数的单元测试用例

public notificationStream(): Observable<Notification> {
return this.notificationSubject.asObservable();

}

angular unit-testing user-interface karma-jasmine
1个回答
0
投票

一种方法可能是这样

it('should check if notificationStream works correctly', () => {
   let mockResponse = { prepare your mock Response}
   this.component.notificationStream().subscribe(resoponse => {
     expect(response).toBe(mockResponse)
   })
   //call function from you component which contains following line 
   //this.notificationSubject.next(mockResponse);
  });

订阅后,您将获得传递给.next()的所有值作为响应>

© www.soinside.com 2019 - 2024. All rights reserved.