views:

50

answers:

1

hi all, i was wondering if there is any difference between performing tests on JavaScript, or Ajax?

I understand that JavaScript is part of the Ajax equation, but is there any forms of execution differences when i am performing tests for JavaScript or JavaScript which is used to enable AJAX?

Best Regards.

+2  A: 

Ajax means your code performs requests to the server, usually using the XMLHttpRequest object. If your test of that code involves a server, you may end up actually testing more server code then JavaScript. If you are fine with that, you can use a testing framework like QUnit(part of the jQuery project, but doesn't require jQuery) or YUI Test that supports asynchronous tests, which are necessary here.

Otherwise you should replace the actual ajax request with a mock request that just returns some testdata, without ever performing an actual request. There are various solutions for that, but I need more context for any specific recommendation. Though, if you are using jQuery's ajax module, you can leverage the xhr-option for replacing the XMLHttpRequest with a mock object.

Jörn Zaefferer