本文介绍了如何在qUnit中停止全局失败?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是qunit的新手,并且正在尝试将其与现有环境集成。

I'm new to qunit, and am attempting to integrate it with an existing environment.

我在使用jQuery的网页上遇到的一个问题是:

One of the issues I get on pages that utilize jQuery is this:

global failure (1, 0, 1)Rerun6 ms
Uncaught ReferenceError: $ is not defined

我认为这是因为我没有在qunit HTML中调用jquery库。是否可以设置一个参数来忽略像这样的全局变量?我试图使HTML尽可能灵活,并且由于许多编辑器具有不同的依赖关系,我只想要qunit来测试我专门给它测试的函数。

I think this is because I'm not calling the jquery library in the qunit HTML. Is it possible to set a parameter to ignore globals like this? I am trying to make the HTML as flexible as possible, and as many editors have different dependencies, I only want qunit to test the functions I specifically give it to test.

推荐答案

我对同样的错误感到困惑,但是没有使用jQuery。负责传播错误的QUnit部分是 window.onerror 回调函数,该函数除其他外,检查 QUnit.config .current.ignoreGlobalErrors 配置值已设置。

I'm stumped at the same error, however without using jQuery. The part of QUnit that is responsible for propagating the error is the window.onerror callback function, which, among other things, check whether the QUnit.config.current.ignoreGlobalErrors configuration value is set.

QUnit配置值在。不幸的是,没有描述 config 对象的当前属性,但从查看源代码来看, ignoreGlobalErrors configuration属性定义是否报告全局错误。运行良好的以下行的测试运行正常:

QUnit configuration values are described in the QUnit.config documentation. Unfortunately, the current property of config object is not described, but from looking at the source, the ignoreGlobalErrors configuration property defines whether global errors are reported or not. A test run with the following lines commented out runs fine:

QUnit.test( "global failure", extend( function() {
    QUnit.pushFailure( error, filePath + ":" + linerNr );
}, { validTest: validTest } ) );

我意识到这只是一个黑客,但如果你正在寻找一个快速'n'肮脏的方式来沉默QUnit,这将有效。

I realize that this is just a hack, but if you're looking for a quick'n'dirty way to silence QUnit, this will work.

这篇关于如何在qUnit中停止全局失败?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 22:05