0
我想讓sinon.fakeServer讓axios返回一個僞造的響應。我可以看到網絡請求404或試圖轉到實際URL的超時,而不是返回模擬的有效負載。Sinon fakeServer與摩卡和axios
我的設置:
describe('test call',() => {
var server;
beforeEach(() => {
server = sinon.fakeServer.create();
server.respondWith(
"https://my.domain.com/myresource",
[200, { "Content-Type": "application/json" }, "[]"]
);
server.autoRespond = true
});
it('returns empty array', done => {
axios
.get('https://my.domain.com/myresource')
.then(res => {
expect(true).to.equal(true);
done()
})
.catch(err=>{
console.log(err.message);
expect(false).to.equal(true);
done();
});
});
afterEach(() => {
server.restore();
});
})