Skip to content

Instantly share code, notes, and snippets.

@fschwiet
Created July 3, 2012 06:02
Show Gist options
  • Save fschwiet/3037986 to your computer and use it in GitHub Desktop.
Save fschwiet/3037986 to your computer and use it in GitHub Desktop.
use SinonJS XHR to spy on outgoing AJAX requests - useful for debugging
// SinonJS's XHR support is great for unit testing code that makes
// AJAX requests. But you can also use it to measure AJAX requests
// made from production code if you insert the below code snippet.
// full docs here: http://sinonjs.org/docs/#server
sinon.useFakeXMLHttpRequest();
sinon.FakeXMLHttpRequest.useFilters = true;
sinon.FakeXMLHttpRequest.addFilter(function (method, url, async, username, password) {
if (!async) {
alert("synchronous request detected to " + url );
}
console.dir({
method: method,
url: url,
async: async,
username: username,
password: password
});
return true;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment