有没有人知道我在哪里可以找到axios.put或post的示例sinon测试的链接或参考? 目前我正在研究反应js,我想尝试测试我的axios.put或发布使用sinon mocking。任何帮助将不胜感激。
答案 0 :(得分:0)
const MyService = {
save: body => axios.post('/save', body).then(response => Promise.resolve(response.data))
}
describe('MyService save', () => {
it('should parse and return the response data', () => {
const stubBody = { nic: 'cage' }
const stubResponse = {status: 200, statusText: 'OK', data: { oscars: 1 } }
const stubPost = sinon.stub(axios, 'post').withArgs('/save', stubBody).returns(Promise.resolve(stubResponse))
expect(MyService.save(stubBody)).to.eventually.satisfy(_ => _.oscars === 1)
stubPost.restore()
})
})