public
Last active

Run asynchronous qunit test serially

  • Download Gist
qunit-async-test.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
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();
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.