简体   繁体   English

如何检测QUnit模块中的所有测试何时完成?

[英]How to detect when all tests within a QUnit module is completed?

For the purposes of test sequencing as well as preventing a test being interrupted. 出于测试排序以及防止测试中断的目的。

Also, is there any way to stop a module or test midway and reset QUnit (including all history results)? 另外,是否有任何方法可以停止模块或中途测试并重置QUnit(包括所有历史记录结果)?

QUnit.moduleDone was the only thing I tried for testing module complete. QUnit.moduleDone是我尝试测试模块完成的唯一方法。 But it applies for every single test within the module, not just the module as a whole. 但这适用于模块内的每个测试,而不仅仅是整个模块。

It depends on whether QUnit is running when the tests are declared. 这取决于在声明测试时QUnit是否正在运行。 If you stop it, declare all the tests, then start it the moduleDone callback will be triggered once at the end of the module. 如果停止它,则声明所有测试,然后将其启动,然后在模块末尾触发一次moduleDone回调。 If it's running while declaring the tests then the tests will be run as soon as they're declared, causing the module to only contain the tests that have been declared so far and it believes the modules done after each test finishes. 如果在声明测试的同时正在运行,则测试将在声明后立即运行,从而导致模块仅包含到目前为止已声明的测试,并且它认为模块在每个测试完成之后就完成了。

The same problem occurs with the done callback, if QUnit is running while tests are being declared this is continuously triggered. 如果在声明测试时QUnit正在运行,则done回调也会发生相同的问题,这会连续触发。

So if you're using either of these callbacks you really need to either load all tests synchronously in the head, so they exist when QUnit autostarts in the load event, or set QUnit.config.autostart = false and not call QUnit.start until all asynchronously loaded scripts have finished declaring their tests. 因此,如果您使用这些回调中的任何一个,则您确实需要在头中同步加载所有测试,因此当QUnit在加载事件中自动启动时它们就存在,或者将QUnit.config.autostart = false设置QUnit.config.autostart = false不调用QUnit.start直到所有异步加载的脚本都已完成声明其测试。

Are you sure about QUnit.moduleDone? 您确定QUnit.moduleDone吗? For me it is called once at the end of the module; 对我来说,它在模块末尾被调用一次; what you are describing sounds like QUnit.testDone. 您所描述的听起来像QUnit.testDone。

As for stopping QUnit and resetting it, what would want the web page would look like afterwards? 至于停止QUnit并重置它,之后该网页将是什么样子?

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

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