Node.js Assert- Modul

❮ Eingebaute Module


Beispiel

Wenn ein Ausdruck zu 0 oder falsch ausgewertet wird, wird ein Fehler ausgegeben und das Programm beendet:

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

Definition und Verwendung

Das Assert-Modul bietet eine Möglichkeit, Ausdrücke zu testen. Wenn der Ausdruck zu 0 oder falsch ausgewertet wird, wird ein Assertionsfehler verursacht und das Programm wird beendet.

Dieses Modul wurde für die interne Verwendung durch Node.js erstellt.


Syntax

Die Syntax zum Einfügen des Assert-Moduls in Ihre Anwendung:

var assert = require('assert');

Assert-Methoden

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()  

❮ Eingebaute Module