Jack Allan
Jack Allan

Reputation: 15014

Check for two asynchronous calls in qunit

How do I program the scenario where I have an action that spawns two asynchronous callbacks and I want the test to end when both callbacks have been called?

asyncTest('Do two asynchronous things', 2, function() {
    doTwoThings(callback1, callback2);
    function callback1() {
        ok(true, 'dummy test');
        start();
    }
    function callback2() {
        ok(true, 'dummy test');
        start();
    }
});

Upvotes: 0

Views: 474

Answers (1)

Jack Allan
Jack Allan

Reputation: 15014

The answer is to call stop with the number of additional starts you expect. asyncTest expects one start so for my case I have to add another call to stop.

asyncTest('Do two asynchronous things', 2, function() {
    stop()
    doTwoThings(callback1, callback2);
    function callback1() {
        ok(true, 'dummy test');
        start();
    }
    function callback2() {
        ok(true, 'dummy test');
        start();
    }
});

Upvotes: 3

Related Questions