ReferenceError: notOk is not defined
Asked Answered
N

2

6

I use QUnit for JavaScript unit testing, have quite a few tests already. Majority of them uses assert in the way:

ok(condition.isTrue());

These tests are run well by Visual Studio embeded tests system (in the "Test Explorer") and by 'external' QUnit engine (which is called by clicking 'QUnit test (click to run)' context menu that is displayed if you hit circle left to the QUnit test).

But if I use assert in another way:

notOk(condition.isFalse());

Then tests are run well only inside of Visual Studio tests system, while attempt to run tests by QUnit give following error:

Died on test #1     at http://localhost:64720/Tests.js:123:1: notOk is not defined
Source:     
ReferenceError: notOk is not defined
    at Object.<anonymous> (http://localhost:64720/Tests.js:129:5)
    at Object.Test.run (http://localhost:64720/qunit.js:790:18)
    at http://localhost:64720/qunit.js:877:10
    at process (http://localhost:64720/qunit.js:593:24)
    at http://localhost:64720/qunit.js:182:5

Why does this happen and how to make "notOk" running properly by QUnit?

Thank you.

Namedropper answered 8/10, 2015 at 2:53 Comment(2)
See this: https://mcmap.net/q/1916682/-qunit-assert-not-okEnterprise
I know about "ok()", but I prefer "notOk()" from readability perspective. Also, why should I extend QUnit if 'notOk' is already in, but doesn't work in some cases. Thank you.Namedropper
S
2

Are you facing the same problem as here: 'equal' is not defined : Ember-qunit does not seem to be importing ?

The solution is to use notOk through assert like this:

test('it is not ok', function(assert) {
   var some_value = false;
   assert.notOk(some_value);
});
Sporadic answered 12/10, 2015 at 17:33 Comment(2)
Did not help, still have the same error: TypeError: assert.notOk is not a function. Using the latest (1.19.0) versionNamedropper
Well, with the amount of code you provide except the failing lines not much more could be quessed. If you really want another solutions, please do provide more information.Sporadic
C
0

I had a similar problem. The issue is that my qunit version was older. I just updated my bower.json for qunit to 1.19.0 (was previously on 1.17.1).

Cheder answered 19/10, 2015 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.