How to stop Global Failures in qUnit?

◇◆丶佛笑我妖孽 提交于 2019-12-04 02:27:57

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 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 } ) );

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.

I had this problem using Chrome and found that it was one of my chrome extensions that was throwing an error and causing problems with QUnit. Try disabling extensions and restarting the browser.

From Qunit 2.x upgrade guide I can read there has been a change in using Qunit object, when using 1.x it works like this:

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

On the other hand when using 2.x:

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

should work instead. :-)

for me it was simply a QUnit problem. just changed lower version of qunit, no error..

before Qunit Test Case code, add the following :

window.onerror = function (msg, url, lineNo, columnNo, error) {
    return false;
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!