Similar to test methods, you can use stop
and start
in your teardown code to pause the test runner until your clean-up code is done (asyncTest
does an implicit call to stop
). QUnit uses a counting semaphore for stop
/start
calls, so you can call stop
multiple times if you've got more than one asynchronous task.
Quick example:
var teardownDone = false;
var tests = 0;
var testContent = function() {
if (tests > 0) {
QUnit.ok(teardownDone);
} else {
QUnit.ok(true);
tests++;
}
};
module('example', {
teardown: function () {
// Without this call and the subsequent start(), tests will fail.
stop();
setTimeout(function () {
teardownDone = true;
start();
}, 1000);
}
});
test('test1', testContent);
test('test2', testContent);