Created
February 9, 2010 15:03
-
-
Save cowboy/299286 to your computer and use it in GitHub Desktop.
Run asynchronous qunit test serially
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test( 'async tests', function() { | |
// My custom async function | |
function ajax(data, successCallback) { | |
$.ajax({ | |
url: 'server.php', | |
data: data, | |
success: successCallback, | |
error: function( xhr, textStatus ){ | |
ok( false, textStatus ); | |
} | |
}); | |
}; | |
// Run next test in tests array, or start(). | |
function next(){ | |
var test = tests.shift(); | |
test ? test() : start(); | |
}; | |
// Tests to run, in order. | |
var tests = [ | |
function(){ | |
ajax({ foo: 1 }, function(){ | |
ok(true); | |
next(); | |
}); | |
}, | |
function(){ | |
ajax({ bar: 2 }, function(){ | |
ok(true); | |
next(); | |
}); | |
}, | |
function(){ | |
ajax({ baz: 3 }, function(){ | |
ok(true); | |
next(); | |
}); | |
}, | |
]; | |
stop(); | |
next(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment