How to stop Global Failures in qUnit?
Asked Answered
J

5

12

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

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

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.

Journeyman answered 23/1, 2013 at 13:35 Comment(4)
What is the environment that you are running your QUnit tests? Is it within Rhino?Tungus
The browser actually. Is this common?Journeyman
How are you importing your JQuery library?Tungus
I actually don't want to import jQuery, I just wanted initially to not include it, and only test the functions I want to that are in the same sheet, that don't use jQuery. With further research I'm not sure this is possible.Journeyman
M
9

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.

Multiped answered 26/6, 2013 at 11:35 Comment(2)
Thanks for the tip about QUnit.config.current.ignoreGlobalErrors! I just set this to false and this solved the problem for meGearwheel
In in qunit-2.3.2.js in the onError function before the line if(config.current.ignoreGlobalErrors) you can do this. Add the line config.current.ignoreGlobalErrors = true; For me this suppresses the global error.Recurrent
R
2

before Qunit Test Case code, add the following :

window.onerror = function (msg, url, lineNo, columnNo, error) {
    return false;
}
Rovner answered 13/9, 2019 at 9:40 Comment(0)
K
1

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.

Karinakarine answered 3/10, 2013 at 4:1 Comment(2)
yup, same for me. an extension was throwing global window errors consistentlyRaptor
Or you could run your tests in Chrome's incognito mode to prevent extensions from running without having to disable them.Gsuit
K
1

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. :-)

Koto answered 25/12, 2015 at 1:25 Comment(0)
N
0

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

Naumann answered 15/1, 2015 at 17:47 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.