Example of using mockjax and qunit to test ajax call

asyncTest(“Test successful getTradePeriod Ajax call should fill out trade period dropdown list”, function(){
$(‘<select id=”tradePeriod”></select>’)

url: ‘/DATData/getTradePeriod’
,type: ‘POST’
,responseTime: 100
,dataType: ‘xml’
+   ‘<data><fromDate>2014-10-01</fromDate><toDate>2014-10-08</toDate></data>’
+   ‘<data><fromDate>2014-10-09</fromDate><toDate>2014-10-16</toDate></data>’
+ ‘</tradePeriods>’

equal($(‘#tradePeriod option’).size(), 0);


setTimeout(function() {
equal($(‘#tradePeriod option’).size(), 2);
}, 200);

Tip: 1. use asyncTest; 2. put expected wait time (longer than response time) in setTimeout function.