如何检测QUnit模块中的所有测试何时完成? [英] How to detect when all tests within a QUnit module is completed?

查看:99
本文介绍了如何检测QUnit模块中的所有测试何时完成?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于测试顺序以及防止测试中断的目的.

For the purposes of test sequencing as well as preventing a test being interrupted.

还有,是否有任何方法可以停止模块或中途进行测试并重置QUnit(包括所有历史记录结果)?

Also, is there any way to stop a module or test midway and reset QUnit (including all history results)?

QUnit.moduleDone是我尝试测试模块完成的唯一方法.但这适用于模块中的每个测试,而不仅仅是整个模块.

QUnit.moduleDone was the only thing I tried for testing module complete. But it applies for every single test within the module, not just the module as a whole.

推荐答案

声明测试时,它取决于QUnit是否正在运行.如果停止它,则声明所有测试,然后将其启动,moduleDone回调将在模块末尾触发一次.如果在声明测试的同时正在运行,则测试将在声明后立即运行,从而导致该模块仅包含到目前为止已声明的测试,并且认为该模块在每个测试完成之后就完成了.

It depends on whether QUnit is running when the tests are declared. If you stop it, declare all the tests, then start it the moduleDone callback will be triggered once at the end of the module. 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.

如果在声明测试的同时QUnit正在运行,则done回调也会发生相同的问题.

The same problem occurs with the done callback, if QUnit is running while tests are being declared this is continuously triggered.

因此,如果您正在使用这些回调中的任何一个,则您确实需要在头中同步加载所有测试,因此当QUnit在加载事件中自动启动时它们就存在,或者设置QUnit.config.autostart = false且不调用QUnit.start直到所有异步加载的脚本已完成声明其测试.

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模块中的所有测试何时完成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆