我的效果是从 params 获取最新信息并将其传递到一个排气映射,然后调用一个服务。
@Effect()
loadPlansOnParams$ = this.actions$.pipe(
ofType(backlogActions.BacklogActionTypes.GET_BOARDS_IN_PARAMS),
withLatestFrom(this.store.select(fromRoot.getRouterState), (action, router) => {
const {
state: {
queryParams: { boards },
},
} = router;
return {
boards,
};
}),
exhaustMap(payload => {
return this.boardService.getBoardsFromParams(payload.boards).pipe(
map((res: SignalRResult) => {
const board = res.item;
return new backlogActions.GetBoardsSuccess(board);
}),
catchError(err => of(new backlogActions.GetBoardsError(err))),
);
}),
);
一切都很酷。但是,我无法用它来测试我的一生。几乎我能找到的每一个例子都是无用的。
这是我的测试...
describe('getting boards from the params', () => {
it('should return an empty array if no params', () => {
const params = { state: { queryParams: {} } };
const successfulSignalRResult = { isSuccessful: true, item: [] };
const action = new backlogActions.GetBoardsInParams();
const outcome = new backlogActions.GetAvailableBoardsSuccess([]);
actions.stream = hot('-a', { a: action });
store.select = jest.fn(() => of(params));
expected = cold('--b', { b: outcome });
boardSvc.getBoardsFromParams = jest.fn(() => successfulSignalRResult);
expect(effects.loadPlansOnParams$).toBeObservable({});
});
});
无论我对 store.select 模拟做什么,我都会返回“您在预期流的位置提供了‘未定义’。”
任何帮助表示赞赏。我真的希望我在弹珠上遗漏了一些东西。