-
Assert-a:actual e:expected m:message o:operator v:value b:block
-
Assert.fail (A, E, M, O)
-
assert (V, m), Assert.ok (V, [m])
-
Assert.equal (A, E, [m])
-
Assert.notequal (A, E, [m])
-
Assert.deepequal (A, E, [m])
-
Assert.notdeepequal (A, E, [m])
-
Assert.strictequal (A, E, [m])
-
Assert.notstrictequal (A, E, [m])
-
Assert.throws (b, [ERROR], [m])
-
Assert.doesnotthrow (b, [m])
-
Assert.iferror (v)
Assert.fail (A, E, M, O)
Throws An exception This displays the values for and separated by the actual
expected
provided operator.
Note:always throws an exception and display the message which would be "actual operator expected" if it's omited.
e.g and assert.fail(1,1,"Always throws this message","=")
assert.fail(1,1,"","+")
Assert (V, [M]), Assert.ok (V, [m])
Tests if value is truthy, it's equivalent toassert.equal(true, !!value, message);
Note:if the value isn ' t a truth-value, it throws and exception and display the message which would be "value = = true" If I T ' s omited.
e.g and assert(0)
assert.ok(0,"Throws me")
Assert.equal (A, E, [m])
Tests shallow, coercive equality with the equal comparison operator ( ==
).
e.g and assert.equal(1,2,"They are not equal")
assert.equal(1,1,"would not show me")
Assert.notequal (A, E, [m])
Tests shallow, coercive non-equality with the not equal comparison operator ( !=
).
Note: In summary, an exception is thrown when the comparison result is false.
Assert.deepequal (A, E, [m])
Tests for deep equality.
Note: not clear!
Assert.notdeepequal (A, E, [m])
Tests for any deep inequality.
Note: not clear!
Assert.strictequal (A, E, [m])
Tests strict equality, as determined by the strict equality operator ( ===
)
Assert.notstrictequal (A, E, [m])
Tests strict non-equality, as determined by the strict not equal operator ( !==
)
Assert.throws (b, [ERROR], [m])
expects block
to throw a error. error
can be constructor, RegExp
or validation function.
Validate instanceof Using constructor:
Assert.throws (function () {throw new Error ("wrong value");},error);
Validate error message using REGEXP:
Assert.throws (function () {throw new Error ("wrong value");},/value/);
Custom Error Validation:
Assert.throws (function () {throw new Error ("Wrong value"),},function (err) {if (err instanceof Error) &&/value/. Test (Err)) {return true;}, "Unexpected error");
Assert.doesnotthrow (b, [M])
expects not block
to throw a error, see for assert.throws
details.
Assert.iferror (v)
Tests if value is no a false value, throws if it is a true value. Useful when testing the first argument, in error
callbacks.
Note:it throws error when the value is a truth-value!
Nodejs Learning Note--assert (assertion)