为什么在大理石测试 Observables 时会出现 3 个额外的帧错误?

问题描述

我正在测试以下 redux-observable 史诗:

export const loginEpic: Epic<LoginActionTypes> = (action$,state$,{ ajax }) => action$.pipe(
  filter(isOfType(LOGIN)),mergeMap(action => login(action.payload.credentials,ajax).pipe(
    map(ajaxResponSEObject => ajaxResponSEObject.response as User),map(user => loginSuccess(user)),catchError((ajaxResponSEObject: AjaxResponse) => of(loginFail(ajaxResponSEObject.response as NodeJS.ErrnoException)))
  ))
);

我编写了两个类似的测试来验证 loginSuccess 和 loginFail 是否正常工作:(我排除了一些模拟操作):

登录成功

      const actionInput$ = hot('-a',actionValues);
      const action$ = new ActionsObservable(actionInput$);

      const state$ = new StateObservable(new BehaviorSubject(null),null);

      const responseInput$ = cold('--a',responseValue);
      const dependencies = { ajax: () => responseInput$ };

      const output$ = loginEpic(action$,dependencies);
      expectObservable(output$).toBe('---b',actionValues);

登录失败

      const actionInput$ = hot('-a',null);

      const responseInput$ = cold('--#',undefined,mockResponse);
      const dependencies = { ajax: () => responseInput$ };

      const output$ = loginEpic(action$,dependencies);
      expectObservable(output$).toBe('------b',actionValues);

它们都在工作,但是,测试框架说它期望比之前的测试多 3 个帧。我不明白为什么。我希望有人能给我解释一下。

解决方法

不幸的是,TestScheduler 是有状态的,因此您会看到之前运行的测试的效果。

我创建了 a fork of your project 来初始化每个测试的实例。