Reactjs 将sinon用于axios.put或post
有人知道我可以在哪里找到axios.put或post的sinon测试样本的链接或参考吗? 目前我正在开发react js,我想尝试使用sinon mocking测试我的axios.put或post。任何帮助都将不胜感激Reactjs 将sinon用于axios.put或post,reactjs,sinon,Reactjs,Sinon,有人知道我可以在哪里找到axios.put或post的sinon测试样本的链接或参考吗? 目前我正在开发react js,我想尝试使用sinon mocking测试我的axios.put或post。任何帮助都将不胜感激 const MyService = { save: body => axios.post('/save', body).then(response => Promise.resolve(response.data)) } describe('MyServic
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()
})
})