无法对Redux可观察的史诗进行单元测试

时间:2018-10-22 04:00:04

标签: unit-testing redux-observable

我是redux-observable的新手,并在第一部史诗片中写下了我的第一个测试。 该史诗主要处理Facebook登录的功能。

export const facebookLoginEpic = action$ => action$.pipe(
  ofType(authActionTypes.FACEBOOK_LOGIN_INIT),
  switchMap(() => from$(FacebookSDK.fbLogin()).pipe(
    mergeMap(data=> {
      navigate('DRAWER');
      return of$(
        fetchUserSuccess(data),
        saveUserInfoSuccess(data),
      );
    }),
    catchError(error => fetchUserFailure(error)),
  )),
);

然后,我正尝试记录输出$以验证我的想法。

test.js

import { ActionsObservable } from 'redux-observable';
import * as authActionTypes from '../authTypes';
import { facebookLoginEpic } from '../authEpics';

it('Should return the fetchUserSuccess and saveUserInfoSuccess actions', () => {
  const action$ = ActionsObservable.of({
    type: authActionTypes.FACEBOOK_LOGIN_INIT,
  });

  const output$ = facebookLoginEpic(action$);
  console.log(output$)
});

但总是会得到错误

xxxxxxx/node_modules/rxjs/internal/util/hostReportError.js:4
    setTimeout(function () { throw err; });
                             ^

TypeError: You provided an invalid object where a stream was expected. You can provide an Observable, Promise, Array, or Iterable.
    at Object.<anonymous>.exports.subscribeTo (/Users/rae/Project/partido/node_modules/rxjs/internal/util/subscribeTo.js:42:15)
    at Object.subscribeToResult (/Users/rae/Project/partido/node_modules/rxjs/internal/util/subscribeToResult.js:10:26)
    at CatchSubscriber.Object.<anonymous>.CatchSubscriber.error (/Users/rae/Project/partido/node_modules/rxjs/internal/operators/catchError.js:57:33)
    at MergeMapSubscriber.Object.<anonymous>.Subscriber._error (/Users/rae/Project/partido/node_modules/rxjs/internal/Subscriber.js:96:26)
    at MergeMapSubscriber.Object.<anonymous>.Subscriber.error (/Users/rae/Project/partido/node_modules/rxjs/internal/Subscriber.js:74:18)
    at /Users/rae/Project/partido/node_modules/rxjs/internal/util/subscribeToPromise.js:10:43
    at tryCallOne (/Users/rae/Project/partido/node_modules/promise/lib/core.js:37:12)
    at /Users/rae/Project/partido/node_modules/promise/lib/core.js:123:15
    at flush (/Users/rae/Project/partido/node_modules/asap/raw.js:50:29)
    at process._tickCallback (internal/process/next_tick.js:172:11)
error Command failed with exit code 1.

我读了很多文章,并花了很多时间解决这个问题。 但是仍然没有任何进展。 在测试或史诗中我做错了什么吗?

0 个答案:

没有答案