ngrx +大理石测试+延迟

时间:2018-11-28 13:32:45

标签: rxjs ngrx jasmine-marbles

假设我有效果

@Effect()
someEffect$ = this.actions$.pipe(ofType(X), switchMap(() => 
of(Y).pipe(delay(3000)))

大理石测试应该如何?

const action = new X();
const result = new Y();

actions$.stream = hot('-x', { x: action });
const expected = cold('-y', { y: result }); // ? adding frames or 3s doesn't work
expect(effects.someEffect$).toBeObservable(expected);

作为回报,我得到

Expected $.lenght = 0 to equal 1. 

1 个答案:

答案 0 :(得分:0)

如果您不想通过调度程序来延迟,也可以执行以下操作:

import { cold, hot, getTestScheduler } from "jasmine-marbles";

scheduler.run((helpers) => {
  const action = new X();
  const result = new Y();

  actions$ = helpers.hot('-x', { x: action });
  helpers.expectObservable(effects.someEffect$).toBe('- 3s y', { y: result });
})
相关问题