【发布时间】:2020-08-28 19:27:10
【问题描述】:
我正在使用 rxjs 中的 EMPTY 来处理 catchError,为了通过失败场景,预期的正确值是多少。
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import { EMPTY } from 'rxjs';
import { map, mergeMap, catchError } from 'rxjs/operators';
import { MoviesService } from './movies.service';
@Injectable()
export class MovieEffects {
loadMovies$ = createEffect(() => this.actions$.pipe(
ofType('[Movies Page] Load Movies'),
mergeMap(() => this.moviesService.getAll()
.pipe(
map(movies => ({ type: '[Movies API] Movies Loaded Success', payload: movies })),
catchError(() => EMPTY)
))
)
);
constructor(
private actions$: Actions,
private moviesService: MoviesService
) {}
}
// unit test
it('should return a empty observable', () => {
this.moviesServiceSpy.and.return(throwError('Error in service'));
action$ = hot('a', a: { loadMovies() });
const expected = cold('|');
expect(loadMovies$).toBeObservable(expected);
})
【问题讨论】:
标签: javascript jasmine rxjs5 ngrx-effects rxjs-marbles