使用redux异步操作和axios进行测试

时间:2017-03-19 04:40:37

标签: redux mocha sinon chai axios

我一直在学习

测试
  • 摩卡
  • 兴农

现在我正在测试一个redux异步应用程序,我想知道提供给某些API调用的参数是否正确,我该怎么做?

我正在考虑类似axios.getCall().args之类的东西来获取为API调用提供的参数,然后验证它们是否正确但我找不到符合我的想法的命令。

1 个答案:

答案 0 :(得分:0)

我发现了如何,

首先存根方法

axios.post = sinon.stub().returns(Promise.resolve({ data: 'test' }));

然后调度异步操作

store.dispatch(updateTodos(currentState))
    .then(() => {
        // this line would get the call and then get the argument
        let args = axios.post.getCalls()[0].args;
        done();
    });
相关问题