开发者

jquery 1.5 mock ajax

开发者 https://www.devze.com 2023-02-07 20:23 出处:网络
In jquery 1.5, what is the recommend approach for mocking ajax requests? Is it to use t开发者_如何学Pythonhe ajax extension transports?

In jquery 1.5, what is the recommend approach for mocking ajax requests? Is it to use t开发者_如何学Pythonhe ajax extension transports? http://api.jquery.com/extending-ajax/#Transports


Have you tried extending $.ajax with the 1.5 update and finding out if you can call .resolve on the jqXHR.

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.


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.


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

http://code.semanticsworks.com/ajaxMock/src/ajaxMock.js

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号