gpt4 book ai didi

javascript - 将 axios POST 请求与 moxios 匹配

转载 作者:数据小太阳 更新时间:2023-10-29 05:11:41 29 4
gpt4 key购买 nike

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

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

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

最佳答案

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

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

配置对象是在 axios 中传递的内容,data 是请求的主体。

关于javascript - 将 axios POST 请求与 moxios 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43450461/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com