Skip to content

Instantly share code, notes, and snippets.

@cowboy
Created February 9, 2010 15:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cowboy/299286 to your computer and use it in GitHub Desktop.
Save cowboy/299286 to your computer and use it in GitHub Desktop.
Run asynchronous qunit test serially
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