我正在尝试为扩展基类的组件编写单元测试。
component.ts
export class DesktopPresentationAreaComponent extends AbstractPresentationComponent {
constructor() {
super(store, webcast);
}
}
基类
export abstract class AbstractPresentationComponent {
constructor(protected store: MainStorageService,
protected webcast: WebcastService) {
this.store.get('state').subscribe();
}
当我运行“ng test”时,它显示以下错误。
TypeError: Cannot read property 'subscribe' of undefined in AbstractPresentationComponent
我该如何解决这个问题?
最佳答案
您需要获取“MainStorageService”实例。然后监视'store.get('state')'。例如
获取服务实例
store = fixture.debugElement.injector.get(MainStorageService);
监视 get 方法
spyOn(store, 'get').and.callFake(() => {
return Observable.from([]);
})
关于angular - 无法为以 Angular 扩展基类的组件运行单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57687719/