Carl Raymond
Carl Raymond

Reputation: 4479

Calling QUnit's assert.async function multiple times

I'm using QUnit to test a javascript library, and I need to verify that a callback is invoked more than one time. According to the QUnit docs (at http://api.qunitjs.com/async/), something like this simplified test case should work:

QUnit.test("assert.async with argument", function (assert) {

var done = assert.async(3);

done();
done();
done();
});

However, the above throws exception, Called the callback returned from assert.async more than once.

I have to resort to building an array of done() functions, and then popping each off and invoking it. Not as nice.

Update

On upgrading QUnit to 2.0.1, the code above will work (modulo a complaint that 0 assertions were made). I had been using version 1.18.

Upvotes: 2

Views: 1124

Answers (1)

Jordan Kasper
Jordan Kasper

Reputation: 13273

Updated

The OP commented below, he just needed to upgrade QUnit!

...

I have a JS fiddle where you can see this working asynchronously (with setTimeout) and one without (your example).

Here is an example which does work (with QUnit 2.0.1 anyway) using setTimeout:

QUnit.test( "multiple call done()", function( assert ) {
  var done = assert.async( 2 );

  setTimeout(function() {
    assert.ok( true, "first call done." );
    done();
  }, 500 );

  setTimeout(function() {
    assert.ok( true, "second call done." );
    done();
  }, 500 );
});

Upvotes: 3

Related Questions