I'm learning how to use sinon.js. I can fake normal AJAX but I need to request a image and I don't get xhr.response (it is undefined). How can I use sinon.js to fake the response of an image?
var url = 'http://www.google.com.hk/logos/2013/antoni_gauds_161st_birthday-1539005.2- hp.jpg';
server.respondWith("GET", url, [200, {}, '']);
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'arraybuffer';
xhr.addEventListener('load', function() {
//this.response is undefined
})
xhr.send(null);
How can I fake this image request?
I think an idea:
describe('...',function(){
var xhr;
before(function(){
xhr = sinon.useFakeXMLHttpRequest();
xhr.onCreate = function (x) {
console.log(x)
};
//....
}
after(function(){
xhr.restore();
});
it('....',function(){
xhr.prototype.response = new ArrayBuffer(1024)
// ...
});
}