Reputation: 70095
I have an asynchronous QUnit test where the test should pass if the operation times out. (I'm testing that if you omit an optional errorCallback
and do something that throws an error, basically nothing happens no matter how long you wait.)
How would I do that? If I use Qunit.config.testTimeout
then the test will fail on timeout. I want to set a timeout and have the test succeed when the timeout is reached.
Upvotes: 4
Views: 2632
Reputation: 418
This is how I do in these cases (roughly):
function timeout(assert,to,error){
var done = assert.async();
var a = setTimeout(function(){
assert.equal(to,undefined,error);
done();
},to);
return function(){
done();
clearTimeout(a);
};
}
then you can:
...
var done = timeout(assert,2000,"not joined");
r.join(function(data){
assert.ok(true,"join confirmed");
done();
})
You may agument timeout
function to timeout(assert,to,toCB)
and execute the toCB
instead of my dummy assert.equal
Upvotes: 0
Reputation: 213
Why not just go with a setTimeout
call making the test succeed?
e.g.:
expect(1);
stop();
doOperation(function () {
start();
ok(false, "should not have come back");
});
setTimeout(function () {
start();
ok(true);
}, timeoutValue);
Upvotes: 5