Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
general knowledge
ASP.NET
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
 AngularJS
 :) Hot Jobs
 
 :) Latest Articles


  

 


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
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


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 |