Hi,
I am doing jquery Qunit testing in my application, i use only asynchronous ajax calls. In a function i use 2 ajax calls. To test the async calls i use start() and stop(). In the callback of every async call i use start() and in test case after function is called, i use stop().
Original method:============
function MyOriginalMethod()
{
Ajax_Async('/Home/Index', null, 'GET', false, MyCallBack1);
Ajax_Async('/Home/MyAction', 'myName=ramesh', 'GET', false, MyCallBack2);
}
var MyCallBack1 =(function(){
var home= $('body').data('result');
$('#master_div').html(home);
start();// corresponding stop is in test case......
});
var MyCallBack2 =(function(){
var userAction= $('body').data('result');
$('#user_div').html(userAction);
start();// corresponding stop is in test case......
});
//Async function
function Ajax_Async(restUrl, params, restType, cacheFlag, callback) {
$.ajax({
type: restType,
async: true, //To make a ASYNC call only... callback will be called after success
url: RootUrl_ + restUrl,
data: params,
cache: cacheFlag, //To clear Cache since the datatype can be Json.For Json datatype by defualt cache is true
success: function (result) {
$('body').data('result', result);//which is used in callback...
new callback;
},
error: function (error) {
alert(error);
}
});
}
Test method:
=========
function MyTestMethod()
{
test('MyOriginalMethod', function(){
MyOriginalMethod();
stop();//start is in callback of async call
});
test('Test the Values', function(){
ok($('#master_div').children().length > 0, 'Values present in Master div');
ok($('#user_div').children().length > 0, 'Values present in User div');
});
}
When both are tested independently they get passed, but when the function as a whole including both is tested it gets failed. It would be great somebody can help me on this..
Thanks in advance..
Ramesh