【问题标题】:Matching axios POST request with moxios将 axios POST 请求与 moxios 匹配
【发布时间】:2017-09-13 00:15:59
【问题描述】:

是否可以使用 moxios 模拟对 POST 请求的回复,该回复不仅可以通过 URL 匹配,还可以通过 POST 正文匹配?事后检查尸体也对我有用。

这就是我现在正在做的事情。据我所知,没有特定于方法的存根方法:

describe('createCode', function () {
    it('should create new code', function () {
        moxios.stubRequest(process.env.API_URL + '/games/GM01/codes', {
            status: 200
        })
    })
})

【问题讨论】:

    标签: javascript axios moxios


    【解决方案1】:

    有一种方法可以使用 moxios 检查最后一个 axios 请求:

    let request = moxios.requests.mostRecent()
    expect(request.config.method).to.equal('post')
    expect(JSON.parse(request.config.data)).to.deep.equal(code)
    

    config 对象是在 axios 中传递的,data 是请求的主体。

    【讨论】:

      猜你喜欢
      • 2016-08-10
      • 2020-06-16
      • 2022-07-24
      • 1970-01-01
      • 2019-11-25
      • 2017-12-08
      • 1970-01-01
      • 2021-08-11
      相关资源
      最近更新 更多