ngrx action:如何测试该动作是否已调度

如何对是否已分派动作进行单元测试?

例如我有这个简单的方法

 public openInfo()
  {
    this.store.dispatch(Infoactions.openInfo({
      Configuration: {
        message: 'This is an info message!'
      }
    }));
  }

我需要编写一个单元测试来验证是否已分派动作:

   it('should dispatch openInfo action',function () {

    // how to check the dispactched actions and their parameters?
    // expect(...)
  });

如何检查已调度的动作?

mjg1mlf2 回答:ngrx action:如何测试该动作是否已调度

您不必。您需要在商店使用间谍。

在store.dispatch上创建间谍并使用

expect(store.dispatch).toHaveBeenCalledWith(...)

您已完成。调度的实际测试属于商店单元测试。

本文链接:https://www.f2er.com/3153970.html

大家都在问