Node.js Assert Complete Reference
Assert module in Node.js provides a bunch of facilities that are useful for the assertion of the function. The assert module provides a set of assertion functions for verifying invariants. If the condition is true it will output nothing else an assertion error is given by the console.
Example:
Javascript
const assert = require( 'assert' ).strict;
var a = "GeeksforGeeks" ;
var b = "Geeks4Geek" ;
try {
assert.strictEqual(a, b);
} catch (error) {
console.log( "Error: " , error)
}
|
Output:
Error: AssertionError [ERR_ASSERTION]: Expected values to be strictly equal: + actual – expected + ‘GeeksforGeeks’ – ‘Geeks4Geek’ ^ at Object. (C:\Users\Lenovo\Downloads\index.js:4:12) at Module._compile (internal/modules/cjs/loader.js:1138:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) at Module.load (internal/modules/cjs/loader.js:986:32) at Function.Module._load (internal/modules/cjs/loader.js:879:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 { generatedMessage: true, code: ‘ERR_ASSERTION’, actual: ‘GeeksforGeeks’, expected: ‘Geeks4Geek’, operator: ‘strictEqual’ }
The Complete List of NodeJS Assert are listed below:an
Last Updated :
05 Dec, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...