Created
July 3, 2012 06:02
-
-
Save fschwiet/3037986 to your computer and use it in GitHub Desktop.
use SinonJS XHR to spy on outgoing AJAX requests - useful for debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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