5/15/2023 0 Comments Nodejs assert![]() This is false because ‘text2’ = ‘number’.ĪssertionError : Both the strings are not identicalĪt Object. If we compile and run the code, it will throw an AssertionError along with the text in the message to the output. In the following example, we are passing two string values and checking their type.Īssert.strictEqual(typeof text1 = 'string', typeof text2 = 'number', 'Both the strings are not identical') If we compile and run the code, No AssertionError will be thrown to the output. In the following example, we are passing two identical strings to the actual and expected parameters of the function.Īssert.strictEqual(text1, text2, 'Both the strings are identical') (/home/cg/root/639c3f570123e/main.js:5:8)Īt Module._compile (internal/modules/cjs/loader.js:702:30)Īt Object.Module._extensions.js (internal/modules/cjs/loader.js:713:10)Īt Module.load (internal/modules/cjs/loader.js:612:32)Īt tryModuleLoad (internal/modules/cjs/loader.js:551:12)Īt Function.Module._load (internal/modules/cjs/loader.js:543:3)Īt (internal/modules/cjs/loader.js:744:10)Īt startup (internal/bootstrap/node.js:238:19)Īt bootstrapNodeJSCore (internal/bootstrap/node.js:572:3) This is false because 34 != 10.ĪssertionError : Both the values are not sameĪt Object. If we compile and run the code, it will throw AssertionError to the output along with the text in message parameter. In the following example, we are passing two distinct integers to the actual and expected parameters of the function.Īssert.strictEqual(int1, int2, 'Both the values are not same') ![]() In the following example, we are passing two identical integers to the actual and expected parameters of the Node.js assert.strictEqual() function.Īssert.strictEqual(num1, num2, 'Both the values are same') This function will return the AssertionError on the terminal if both actual and expected are not matched. ![]() Message − (optional) String or Error type can be passed as an input into this parameter. The value can be of any type.Įxpected − (required) The value passed in this parameter will be compared to the actual value. The same are described below.Īctual − (required) The value passed in this parameter will be evaluated. Syntaxįollowing is the syntax of Node.js assert.strictEqaul() function −Īssert.strictEqual(actual, expected) This function is an alias of Node.js epStrictEqaul() function. If both the parameters are not similar, then it will throw an AssertionError to the output. Whenever both the parameters are similar, the function doesn’t throw AssertionError. This function will test equality on both of its parameters actual and expected. Also, comparing NaN (Not-A-Number) to any other value, including itself, returns false. This function compares both the data type and value of two variables or objects and returns true only if they are exactly the same. ![]() The Node.js strictEqual() function is used to determine if two values are equal using a stricter comparison than the = operator. The Node.js assert.strictEqual() function is an inbuilt function of the assert module of Node.js. The assert module provides a set of assertion functions for verifying invariants.
0 Comments
Leave a Reply. |