Node.js Assert- module

❮ Ingebouwde modules


Voorbeeld

Als een expressie 0 of onwaar is, wordt een fout gegenereerd en wordt het programma beëindigd:

var assert = require('assert');
assert(5 > 7);

Definitie en gebruik

De assert-module biedt een manier om uitdrukkingen te testen. Als de expressie 0 of onwaar is, wordt een beweringfout veroorzaakt en wordt het programma beëindigd.

Deze module is gebouwd om intern te worden gebruikt door Node.js.


Syntaxis

De syntaxis voor het opnemen van de assert-module in uw toepassing:

var assert = require('assert');

Bevestigingsmethoden

Method Description
assert() Checks if a value is true. Same as assert.ok()
deepEqual() Checks if two values are equal
deepStrictEqual() Checks if two values are equal, using the strict equal operator (===)
doesNotThrow()  
equal() Checks if two values are equal, using the equal operator (==)
fail() Throws an Assertion Error
ifError() Throws a specified error if the specified error evaluates to true
notDeepEqual() Checks if two values are not equal
notDeepStrictEqual() Checks if two values are not equal, using the strict not equal operator (!==)
notEqual() Checks if two values are not equal, using the not equal operator (!=)
notStrictEqual() Checks if two values are not equal, using the strict not equal operator (!==)
ok() Checks if a value is true
strictEqual() Checks if two values are equal, using the strict equal operator (===)
throws()  

❮ Ingebouwde modules