In jquery 1.5, what is the recommend approach for mocking ajax requests? Is it to use the ajax extension transports? http://api.jquery.com/extending-ajax/#Transports
jquery 1.5 mock ajax
1.6k views Asked by joshjdevl At
3
There are 3 answers
0

I have created on mock for jQuery AJAX, and I used three extension points that jQuery 1.5+ provided (prefitler, transport, and converters). Please check this out
https://github.com/fredyang/ajaxMock
for detail usage, please check the test case, all the test cases are passed, and they are just the living document about how to use it.
Here is the url of the test case
https://github.com/fredyang/ajaxMock/blob/master/test/test.js
Here is the link that run the test case
http://code.semanticsworks.com/ajaxMock/test/index.html
and here is the link of the mock
0

I have a similar question here :
How to test jquery and ajax calls using JsTestDriver?
And I found solutions, maybe there are others better, but it works with our JsTestDriver tests.
Have you tried extending
$.ajax
with the 1.5 update and finding out if you can call.resolve
on thejqXHR
.As long as you get it to not remove the
.promise
read-only Deferred object you should be able to fake a completion of the ajax request.Alternative you can always just mock out a
node.js
server.Anywhere you can hook into and get the
jqXHR
object you might be able to call.resolve
on it with the mock paramaters.