简体   繁体   English

QUnit完成所有测试运行时的回调。 (`QUnit.done()`不能按预期工作)

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

QUnit has a number of callbacks , such as: QUnit有许多回调 ,例如:

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

The problem is that QUnit.done() does not work as expected. 问题是QUnit.done()无法按预期工作。 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. 如下所示,一旦页面(使用jQuery)加载后,我便将所有测试注册到QUnit中,因为它们(不幸的是)依赖于首先加载的应用程序。 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? 这是每个测试后调用done()的原因吗? 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. 诀窍是设置QUnit.config.autostart = false ,然后在加载所有测试并加载应用程序后启动测试。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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