ngrx + 弹珠测试 + 延迟

Cor*_*lom 6 rxjs ngrx jasmine-marbles

假设我有效果

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

大理石测试应该是什么样子的?

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);
Run Code Online (Sandbox Code Playgroud)

作为回报,我得到

Expected $.lenght = 0 to equal 1. 
Run Code Online (Sandbox Code Playgroud)

bys*_*bys 6

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

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

const scheduler = getTestScheduler();
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 });
})
Run Code Online (Sandbox Code Playgroud)