角单元测试:如何观察一个可观察对象是否已订阅?

时间:2019-07-18 14:21:20

标签: javascript angular unit-testing rxjs jasmine

如何通过以下代码检查this.someService.someProperties是否已订阅:

SomeMethod(){
   this.someService.someProperties.subscribe((data) => {
     //...
    });
}


it('Should call subscribe() ', () => { 

    someService.push({});
    let currentPropertiesSpy = spyOn(someService, 'someProperty') ;
    component.someMethod();
    expect(currentPropertiesSpy).toHaveBeenCalled();
  });

class someServiceStub { 
  private propertiesSource = new BehaviorSubject(this.defaultProperties);
  currentProperties = this.propertiesSource.asObservable();
  push(val){
    this.propertiesSource.next(val);
  }
}

0 个答案:

没有答案
相关问题