[英]angular 5 unit tests fail when rxjs switchmap used
我正在嘗試測試一個組件,該組件在存儲上調度了一個動作,然后從該switchmap內部返回了一些數據
此問題與對該組件進行單元測試有關。 如果我刪除switchmap,代碼可以正常運行,否則將失敗
undefined is not a constructor
這是我的規格文件
it('should dispatch xyz action oninit', async(() => {
mockStore.select.and.returnValue(MockService.xyz);
component.ngOnInit();
expect(mockStore.select).toHaveBeenCalledTimes(1);
expect(mockStore.select).toHaveBeenCalledWith(fromStore.xyz);
expect(component.data$).toEqual(Observable.of(MockService.xyz));
}));
這是組件oninit方法
ngOnInit(): void {
this.data$ = this.store.select(fromStore.xyz)
.switchMap((val) => { return Observable.of{zyz};}
}
如果我刪除此switchmap測試運行正常,我在這里看到的錯誤是
undefined is not a constructor (evaluating 'this.store.select(fromStore.zyz)
.switchMap')
我正在使用phantomjs和茉莉花運行我的規格
問題是由於未在我的component.ts文件中導入地圖運算符。 在單元測試中,此運算符無法解析
import { map } from 'rxjs/operators';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.