Waiting for a timeout in QUnit

I have a QUnit asynchronous test in which the test should pass if the operation timed out. (I'm testing that if you omit the optional errorCallback and do what causes the error, basically nothing happens no matter how long you wait.)

How can I do it? If I use Qunit.config.testTimeout , then the test will fail. I want to set a timeout and run a test when the timeout is reached.

+4
source share
2 answers

Why not just go with a call to setTimeout so that the test succeeds?

eg:.

 expect(1); stop(); doOperation(function () { start(); ok(false, "should not have come back"); }); setTimeout(function () { start(); ok(true); }, timeoutValue); 
+5
source

Here is how I do in these cases (approximately):

 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 can use the function timeout to timeout(assert,to,toCB) and execute toCB instead of my assert.equal dummy

0
source

Source: https://habr.com/ru/post/1390780/


All Articles