У меня есть эффект, который берет последнее из параметров и передает его в выхлопную карту, которая затем вызывает службу.
@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, я получаю ответ: «Вы указали undefined там, где ожидался поток».
Любая помощь приветствуется. Я очень надеюсь, что мне что-то не хватает по мрамору.