简体   繁体   中英

Callback for when QUnit has finished running all tests. (`QUnit.done()` not working as expected)

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM