【发布时间】:2019-08-22 23:32:01
【问题描述】:
要测试的组件:
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
});
【问题讨论】:
-
请给minimal reproducible example;这是怎么接线的?我不会测试
showPopup属性,我会测试弹出窗口是否显示。你也可能需要detectChanges。
标签: javascript angular unit-testing jasmine karma-jasmine