QUnit, to argue is not in order?

Sorry if this is obvious, but is there a NOTOK function or an equivalent function in QUnit if we want to claim that the method returns false?

I see no way to deny OK in the documentation .

I tried:

!ok... 

but it didn’t work.

+3
source share
5 answers

You can use: ok(!method_expected_to_be_false)

+7
source

According to the documentation:

The most basic statement in QUnit, ok () requires only one argument. If the argument evaluates to true, the statement passes; otherwise fails.

You can verify that the method returns false by writing an expression that evaluates to true if the method returns false , and vice versa. The simplest expression for this is the NOT operator, which in JavaScript is expressed through !

 test( "Test method returns false ", function() { ok( method() == false, "Method returned false" ); // or using a the negation operator ok( !method(), "Method returned false" ); }); 
+2
source

If this is really what you really need, you can add it using QUnit.extend() :

 QUnit.extend(QUnit.assert, { notOk: function (result, message) { message = message || (!result ? "okay" : "failed, expected argument to be falsey, was: " + QUnit.dump.parse(result)); QUnit.push(!result, result, false, message); }, }); 
0
source

starting with qunit 1.18 , there is a special function:

 assert.notOk(valueToBeTested); 
0
source

A better approach would be to use:

 notOk(<something>); 

as this will be more expressive than declaring:

 ok(!<something>); 
-1
source

All Articles