Hi Guest 1 HomePage 1 Jobs 1 WalkIn 1Articles  

 :) Latest Topic
Node.js Tutorial
Parts of Node.js
Features of Node.js
Install Node.js Windows
Install Node.js Linux
Node.js First Example
Node.js Console
Node.js JavaScript Learn
Node.js REPL
Node.js NPM
Node.js CL Options1
Node.js CL Option2
Node.js Globals
Node.js OS
Node.js Timer
Node.js Errors
Node.js DNS
Node.js Net
Node.js Crypto
Node.js TLS/SSL
Node.js Debugger
Node.js Process
Node.js Process Example
Node.js Process Example2
Node.js Child Process
Child Process EXEC
Child Process SPAWN
Child Process Fork
Node.js Buffers
Node.js Streams
Node.js Reading Stream
Node.js Writing Stream
Node.js Piping Stream
Node.js Chaining Streams
Node.js File System Part1
Node.js File System Part2
Node.js File System Part3
Node.js Path
Node.js StringDecoder
Node.js Query String
Node.js ZLIB
Node.js Assertion
Node.js V8
Node.js Callbacks
Node.js Events
Node.js Punycode
Node.js TTY
Node.js Web Module
Node.js Upload Files
Node.js Email Send
Node.js BuiltIn Modules
Node.js Assert Code
Node.js Assert Function
Node.js console.time()
Node.js console.table()
Node.js DNS Code
Node.js cipher.final()
Node.js URL.hash API
Node.js URL.host API
Node.js URL.origin API
Node.js MySQL
Folders in Node.js
Folders Node.js part3
Rename Folder Node.js
Remove Folder Node.js
Read Email File
File Upload Container
 


  

 
Node.js Assert Function
Question Posted on 07 May 2024

Home >> Tutorial >> Node.js Tutorial >> Node.js Assert Function


Node.js Assert Function

Node.js assert.deepStrictEqual() Function


When we say about the assert module this will provides a set of assertion functions to varifying invariants. And this assert.deepStrictEqual() function will tests for deep equality between the actual and expected parameters. IF the condition is true this will not produce an output else an assertion error is raised.

Below is the syntax for Node.js assert.deepStrictEqual() function


assert.deepStrictEqual(actual, expected[, message])



Above function will accept the following parameters as mentioned above and described as given below:-

(1)Actual:-This parameter will holds the actual value which need to be evaluated. And this is of any type.

(2)Expected:-This parameter will holds the expected value which is matched against actual value. And this is of any type.

(3)Message:-This parameter will holds the error message of string or error type. And this is and optional parameter.

This function will returns assertion error of object type as the Return value.

Use of Assert module:-

(1)You need to install Assert module and to intsall this package by using below command.

npm install assert


(2)Although installation is an optional step as it is inbuilt Node.js module.
(3)Once you install the assert module, you can check the seert version by below command.

npm version assert



Now we will create one sample code to check deepStrictEqual() function. Below is the code and file name is deepStrictFunction.js.


// Requiring the module
const assert = require('assert').strict;

// Function call
try {
assert.deepStrictEqual({ a: 1 }, { a: '1' });
} catch(error) {
console.log("Error: ", error)
}



Once we run the above file with Node.js command prompt we will use below command


Node deepStrictFunction.js



Once we run above command we will get the error as given below


Node.js Assert

Now we will take one more example where we have write the correct code with no error. And we use deepStrictEqual() function and name this file is deepFunction.js and code is given below.


// Requiring the module
const assert = require('assert').strict;

// Function call
try {
assert.deepStrictEqual({ a: '3' }, { a: '3' });
console.log("No Error Occurred")
} catch(error) {
console.log("Error: ", error)
}



Once we run the above in Node.js command prompt we will get the below output.


Node.js Assert function





Other Important Questions
Parts of Node.js
Install Node.js Linux
Node.js First Example
Node.js Globals
Node.js DNS







 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |