【问题标题】:ngrx + marble testing + delayngrx + 大理石测试 + 延迟
【发布时间】:2019-09-13 17:14:50
【问题描述】:

假设我有效果

@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. 

【问题讨论】:

标签: rxjs ngrx jasmine-marbles


【解决方案1】:

如果你不想让调度器延迟你也可以这样做:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-22
    • 1970-01-01
    • 2021-04-16
    • 1970-01-01
    • 2020-02-11
    • 2018-09-19
    • 2019-09-16
    • 1970-01-01
    相关资源
    最近更新 更多