Qunit —-> testing Ajax functions

If you need to test Ajax request you should do in this way. First you ought to create a HTML file It will be the test datafile therefore it contain only simple JSON



Then you can write your test:

 var JSON_obj_val_integer = 0;  
 remoteGetInteger = function ( completedHandler) {  
           var post = $.ajax({  
                url: 'data/test_ajax_data.html',  
                type: "post",  
                dataType: "json",  
                data: { refresh: "1" },  
                success: function(JSON_obj) {  
                     $.each(JSON_obj,function() {  
                               JSON_obj_val_integer = JSON_obj.val;  
           post.done(function (result) {  
           post.fail(function () {  
 test( 'JSON_obj_val_String value = refreshed', function() {       
      var result = '';  
      remoteGetString( function (r) {  
           result = r;  
           equal(result, 'refreshed', "check Ajax String");  

Thats it.

This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

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