jquery - Qunit Assert mockajax response -


to test jquery ajax reponse, using mock ajax qunit. have assert mock ajax reponse, in test case,assert statements running first , getting response mock ajax.

how make sure mock ajax response available before calling assert statements in qunit

you'll need asynctest versus simple test call. here's example 1 use:

... asynctest("test title", function() {   $.mockjaxclear(); // clear existing mock jax entries (could in setup method)   $.mockjax({ // pass in request matcher / response object     url: '/some/file.php',     type: 'post',     status: 200,     datatype: 'json',     response: function(req) {       this.responsetext = json.stringify({some: "data"});     }   });    $.ajax({     url: '/some/file.php',     type: 'post',     datatype: 'json',     success: function(d) {       a.deepequal(d, {some: "data"}, "object data correct in callback");        // other tests        start(); // tells qunit start up, async done   });   ... }); 

and documentation of async control in qunit.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -