如何对是否已分派动作进行单元测试?
例如我有这个简单的方法
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(...)
});
如何检查已调度的动作?
答案 0 :(得分:0)
您不必。您需要在商店使用间谍。
在store.dispatch上创建间谍并使用
expect(store.dispatch).toHaveBeenCalledWith(...)
您已完成。调度的实际测试属于商店单元测试。