【问题标题】:Tests with redux async action and axios使用 redux 异步操作和 axios 进行测试
【发布时间】:2017-03-19 04:40:36
【问题描述】:

我一直在学习测试

  • 摩卡
  • 诗乃

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

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

【问题讨论】:

    标签: redux mocha.js sinon chai axios


    【解决方案1】:

    我发现了,

    首先存根方法

    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();
        });
    

    【讨论】:

      猜你喜欢
      • 2019-10-31
      • 2017-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-14
      • 2017-01-26
      • 2018-02-04
      相关资源
      最近更新 更多