测试NGRX效果延迟发出动作或不发出任何东西

一月

我有一个NGRX效果-根据状态-延迟发出动作或不发出任何动作。我想写一个涵盖两种情况的测试。

这是效果:

myEffect$ = createEffect(() =>
  this.actions$.pipe(
    ofType(MyAction),
    filter(state => state.foo === false),
    delay(4000),
    map(state => myOtherAction())
  )
);

在延迟情况下应发出otherAction的情况下的测试工作正常:

describe('emit my action', () => {
   const action = MyAction();

   it('should return a stream with myOtherAction', () => {
      const scheduler = getTestScheduler();
      scheduler.run(helpers => {
        // build the observable with the action
        actions = hot('-a', { a: action });

        // define what is the expected outcome of the effect
        const expected = {
           b: MyOtherAction()
        };
        helpers.expectObservable(effects.myEffect$).toBe('- 4000ms b', expected);
      });
   });
});

但是我不知道如何测试其他状态,在该状态下不应发出其他动作(流的长度为零):

   it('should return an empty stream', () => {
      store.setState({
        myFeature: {
           foo: true
        }
      });
      // ???
   });

请帮忙 :)

一月

由于来自AliF50的提示,我用filter“ Noop Action”(=不带任何侦听器的正常动作)替换了链中的(阻止Observable发出)。因此foo,我不检查过滤器中属性,而是noopAction在foo为true时在地图中返回,而在false为false时在otherAction中返回。

效果:

myEffect$ = createEffect(() =>
  this.actions$.pipe(
    ofType(MyAction),
    //filter(state => state.foo === false),
    delay(4000),
    map(state => state.foo !== false ? noopAction() : myOtherAction())
  )
);

考试:

describe('emit my action', () => {
  const action = MyAction();

  it('should return a stream with myOtherAction', () => {
    const scheduler = getTestScheduler();
    scheduler.run(helpers => {
      // build the observable with the action
      actions = hot('-a', { a: action });
      // define what is the expected outcome of the effect
      const expected = {
        b: MyOtherAction()
      };
      helpers.expectObservable(effects.myEffect$).toBe('- 4000ms b', expected);
    });
  });

  it('should return a stream with noop action as foo is true', () => {
    store.setState({
      myFeature: {
        foo: true
      }
    });
    const scheduler = getTestScheduler();
    scheduler.run(helpers => {
      // build the observable with the action
      actions = hot('-a', { a: action });
      // define what is the expected outcome of the effect
      const expected = {
        b: NoopAction()
      };
      helpers.expectObservable(effects.myEffect$).toBe('- 4000ms b', expected);
    });
  });

});

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

MongoClient.connect不会发出任何东西吗?

来自分类Dev

带有FX-6300和MSI HD 7850的MSI 970A-G43不会开机自检或显示任何东西或发出任何噪音

来自分类Dev

RxJS:与计时器一起使用时,groupBy不发出任何值

来自分类Dev

QDesktopWidget在屏幕分辨率更改或监视计数时不发出任何信号

来自分类Dev

提交按钮不发送任何东西

来自分类Dev

百胜为什么不列出任何东西?

来自分类Dev

PHP的JSON编码不输出任何东西

来自分类Dev

为什么文件读取不输出任何东西?

来自分类Dev

使用延迟测试 NGRX 效果

来自分类Dev

测试方法不返回任何东西

来自分类Dev

VBA功能“ sendkeys”不发送任何东西

来自分类Dev

发出任何请求之前验证服务器身份

来自分类Dev

QTcpSocket不会发出任何错误或连接的信号

来自分类Dev

QFileDialog不发出信号

来自分类Dev

QFileDialog不发出信号

来自分类Dev

如何以特定的 product.id 形式发出动作调用?

来自分类Dev

如果在给定时间范围内未发出任何值,则rxjs发出恒定值

来自分类Dev

我正在尝试通过 Firebase 云功能发出通知,但我的代码没有发出任何通知

来自分类Dev

RxJS forkJoin不发出值

来自分类Dev

Scrapy不发出POST请求

来自分类Dev

Tornado:不发出异步请求

来自分类Dev

Apollo Query 不发出请求

来自分类Dev

测试失败动作-大理石-NGRX效果

来自分类Dev

addValueEventListener 带来任何东西

来自分类Dev

SSL超过任何东西?

来自分类Dev

为什么在使用StreamController时我自己的流没有发出任何值?

来自分类Dev

发送消息时Socket.io不会发出任何信息

来自分类Dev

Android文字转语音播放没有错误,但不会发出任何声音

来自分类Dev

使用HTTP模块的AWS Lambda函数未发出任何请求

Related 相关文章

热门标签

归档