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.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s