jest
和
jasmine-marbles
测试我的
ngrx-effects
. 到目前为止还不错,但我有一个特殊的案例需要使用
withLatestFrom
访问
Store
@Effect()
createDataSourceSuccess$ = this.actions$
.ofType<sourceActions.CreateDataSourceSuccess>(
sourceActions.DataSourceActionTypes.CreateDataSourceSuccess
)
.pipe(
map(action => action.dataSource),
withLatestFrom(this.store.select(getSourceUploadProgress)),
switchMap(([source, progress]: [DataSource, UploadProgress]) =>
of(
new sourceActions.StartSourceUploadProgress({
id: source.fileId,
uploadProgress: progress,
})
)
)
);
it('should return StartSourceUploadProgress for CreateDataSourceSuccess', () => {
const dataSource = dataSources[0];
const action = new dataSourceActions.CreateDataSourceSuccess(dataSource);
const outcome = new dataSourceActions.StartSourceUploadProgress({
id: dataSource.fileId,
uploadProgress: null,
});
store.select = jest.fn(_selector => of(null));
actions.stream = hot('-a-', { a: action });
const expected = cold('--b', { b: outcome });
expect(effects.createDataSourceSuccess$).toBeObservable(expected);
});
我还注意到我成功地为
商场
为了
Actions
因为其他的测试都很好。这个和其他的唯一区别是
商场
和
最晚从
最后这是我得到的错误输出:
DataSourceEffects ⺠should return StartSourceUploadProgress for CreateDataSourceSuccess
TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
有什么想法吗?