Why are there 3 additional frames when marble testing Observables that error out?

414 views Asked by At

I am testing the following redux-observable epic:

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)))
  ))
);

I have written two similar tests to verify that loginSuccess and loginFail are working: (I've excluded some mock actions):

loginSuccess

      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$, state$, dependencies);
      expectObservable(output$).toBe('---b', actionValues);

loginFail

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

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

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

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

They are both working, however, the testing framework says that it is expecting 3 additional frames than the previous test. I don't understand why. I am hoping someone can explain it to me.

1

There are 1 answers

0
NickL On BEST ANSWER

Unfortunately the TestScheduler is stateful, so you're seeing the effects of previously run tests.

I've created a fork of your project that initialises an instance per test.