Fake XHR and server
Fake XHR and server
Fake XMLHttpRequest
Provides a fake implementation of XMLHttpRequest
and provides several interfaces for manipulating objects created by it.
Also fakes native XMLHttpRequest
and ActiveXObject
(when available, and only for XMLHTTP
progids). Helps with testing requests made with XHR
.
The fake server and XHR can be used completely stand-alone by downloading sinon-server.js
.
{ setUp: function () { this.xhr = sinon.useFakeXMLHttpRequest(); var requests = this.requests = []; this.xhr.onCreate = function (xhr) { requests.push(xhr); }; }, tearDown: function () { this.xhr.restore(); }, "test should fetch comments from server" : function () { var callback = sinon.spy(); myLib.getCo