0

QUnit has a number of callbacks, such as:

  • QUnit.done()
  • QUnit.moduleDone()
  • QUnit.testDone()

The problem is that QUnit.done() does not work as expected. It actually fires after each test. Is this expected behaviour?

I register all tests into QUnit once the page is loaded (with jQuery) as like below since they (unfortunately) depend on the app being loaded first. And they are split among multiple handlers so tests can be put in different files.

$(function(){
    QUnit.module( "Module 1" );
        QUnit.test("Test 1", function( assert ){
            assert.ok(true);
        });
    });
});

$(function(){
    QUnit.module( "Module 2" );
        QUnit.test("Test 2", function( assert ){
            assert.ok(true);
        });
    });
});

Would this be the reason for done() being called after each test? Is there any way around this, besides having all tests in one file?

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72
Jodes
  • 14,118
  • 26
  • 97
  • 156
  • You could call a function when all tests have completed – guest271314 Sep 02 '16 at 00:28
  • Where do you register the `done` handler? Is it *inside* one of those jQuery ready methods, or outside? Can you show us? – Jordan Kasper Sep 02 '16 at 12:53
  • Just to be clear, the `done` callback _does_ work. Here's [a fiddle showing that](https://jsfiddle.net/rp2mfrv1/). Also, you have a problem in your example test code above... there is an extra `});` within each ready function. – Jordan Kasper Sep 02 '16 at 13:15

1 Answers1

0

I found the answer to this in a similar question.

The trick is to set QUnit.config.autostart = false and then once all tests are loaded and the application is loaded, start the tests.

Community
  • 1
  • 1
Jodes
  • 14,118
  • 26
  • 97
  • 156