Тестирование с трубным оператором - PullRequest
0 голосов
/ 14 октября 2018

Я пытаюсь проверить эффект с помощью Жасмин.

К сожалению, мне не удается получить завершение, так как я не знаю, как насмехаться над оператором pipeable ...

@Effect()
initData$: Observable<Action> = this.actions$.pipe(
    ofType(INIT_DATA_ACTION),
    tap(() => {
        this.loadingService.showLoading();
    }),
    switchMap((data: any) => {
        return this.store.pipe(
            select(getAppDataResolved),
            take(1),
            switchMap((resolved: boolean) => {
                console.log('resolved');
                if (!resolved) {
                    return this.dataService.getInitData(this.loginService.user.id).pipe(
                        tap(() => {
                            this.loadingService.hideLoading();
                        }),
                        switchMap((response: any) => {

                            return Observable.from([
                                new AislesInitDataAction(response.userAisles),
                                new ItemsInitDataAction(response.userItems),
                                new ListsInitDataAction(response.userLists),
                                new ShopsInitDataAction(response.userShops),
                                new InitDataResolvedAction(),
                            ]);
                        }
                    ));
                } else {
                    this.loadingService.hideLoading();
                    return of(new InitDataResolvedAction());
                }
            }
            ));
    }),

Мой тест:

fit('should return InitDataResolvedAction if resolved is true', () => {
    const spy = spyOn(store, 'pipe').and.returnValue(of(true));
    const spyOnLoadingService = spyOn(loadingService, 'showLoading');
    const action = new InitDataAction();
    const completion = new InitDataResolvedAction();

    actions$ = new ReplaySubject(1);
    actions$.next(action);

    effects.initData$.subscribe((a) => {
        console.log(a)
        // expect(a).toEqual(completion);
    });
});

Все, что я получаю, является правдой, когда я смоделировал пипетированную функцию.

Есть какие-нибудь идеи, как имитировать операторы, используемые в pipe ()?

Заранее спасибо

...