如何对一个动作是否派遣进行单元测试?
例如我有这个简单的方法
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(...)
});
如何检查已调度的动作?
不用了 您需要在商店使用间谍。
在store.dispatch上创建一个间谍并使用
expect(store.dispatch).toHaveBeenCalledWith(...)
您完成了。调度的实际测试属于商店单元测试。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句