Why is Node.js Assert not notOk () method?

I am learning testing in Node.js using the mochaand module assert. asserthas the following types of methods:

assert.equal();
assert.deepEqual();
assert.deepStrict();
assert.strict();
assert.ok(); // Is the value true?

And then there are some opposites:

assert.notEqual();
assert.notDeepEqual();
assert.notDeepStrict();
assert.notStrict();

But there is one missing ... Why is there no method notOk()for testing if the resulting value falseor not?

This made me think that there might be something fundamental that I skipped about in unit testing as a whole, because maybe I only need to test ever if the values ​​are true and are never false ...

I am currently just doing this to check for statements falsey:

assert.ok(!myValue);

, ? , notOk(), not?

+4
1

, , .ok(value, message) assert.equal(!!value, true, message). , .

, , ok(), , true . , . , !myValue, , :

assert.ok(myValue === false);

, , , , . notOk() . , notOk .

, not, , - . notEqual , , notOk . ok() , .

, .


, , :

// 4. Pure assertion tests whether a value is truthy, as determined
// by !!guard.
// assert.ok(guard, message_opt);
// This statement is equivalent to assert.equal(true, !!guard,
// message_opt);. To test strictly for the value true, use
// assert.strictEqual(true, guard, message_opt);.

function ok(value, message) {
    if (!value) fail(value, true, message, '==', assert.ok);
}
assert.ok = ok;
+2

Source: https://habr.com/ru/post/1660367/


All Articles