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 AtThere are 3 best solutions below
On
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.
On
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
Have you tried extending
$.ajaxwith the 1.5 update and finding out if you can call.resolveon thejqXHR.As long as you get it to not remove the
.promiseread-only Deferred object you should be able to fake a completion of the ajax request.Alternative you can always just mock out a
node.jsserver.Anywhere you can hook into and get the
jqXHRobject you might be able to call.resolveon it with the mock paramaters.