Проверяемый компонент:
export class ComponentDetailsComponent implements OnInit {
ngOnInit() {
this.componentDetailsService.currentProperties.subscribe((data) => {
this.loader.hideLoader();
this.showPopup = data.showPopup;
.....more code....
}
Спецификация:
class ComponentDetailsServiceStub {
defaultProperties ={
showToolbar: false,
showPopup: true, //show popup is set to true here
refresh: false,
};
propertiesSource = new BehaviorSubject(this.defaultProperties);
currentProperties = this.propertiesSource.asObservable();
setDefaultCancelClicked(){}
}
it('should set showPopup to correct value', () => {
componentDetailsService.propertiesSource.next({
showToolbar: true,
showPopup: false, // show popup is set to false
refresh: false,
});
expect(subject.showPopup).toBe(true) ///this always passes
});