Node.js Assert Module
Voorbeeld
As 'n uitdrukking na 0 of vals evalueer, word 'n fout gegooi en die program word beëindig:
var assert = require('assert');
assert(5 > 7);
Definisie en gebruik
Die assert-module bied 'n manier om uitdrukkings te toets. As die uitdrukking evalueer na 0, of vals, word 'n beweringsmislukking veroorsaak, en die program word beëindig.
Hierdie module is gebou om intern deur Node.js te gebruik.
Sintaksis
Die sintaksis vir die insluiting van die assert-module in jou toepassing:
var assert = require('assert');
Bevestig metodes
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() |