var assert = require (' assert ');
/*node, we can use the Assert module to test the code.
Equal () and notequal () are judged for equality and inequality respectively,
The first parameter is expected, the second argument is the real value, and the third parameter is the exception information */
Assert.equal (1,2,[console.log (' OK ')]);//The expected and true values, whether equal or unequal, output information, why?
Assert.equal (1,2,[' not Equal '));//The expected and true values are not equal, throwing exception information
The/*ok () method is a concise way to compare truth values, equivalent to comparing the current value to true with = =. */
Assert.ok (', ' w ');//Space is False
Assert.ok (' This was a string ', ' Strings that was not empty and is truthy '); True
Assert.ok (0, ' Zero is not truthy ');//0 to False
Assert.fale (' Not Equal ', Console.log (' Error '));
/*node provides a comparison method for object objects deepequal () and notdeepequal (),
They use the following steps to compare objects, throwing an exception with a step mismatch:
1. Use = = = comparison;
2. Compare whether they are buffers, if it is the comparison length, followed by the comparison of each byte per byte;
3. Compare by = =; 4. Finally, if the arguments are object objects, they are compared to the property length and property values.
As you can see, these two methods may be less performance, so use them only when you need them. */
Assert.deepequal (1,2,[' not Equal ');
/*assert.throws (block[, error][, message])
Declares a block used to throw an error (error), and error can be a constructor, regular expression, or other validator. */
Assert.throws (function () {
throw new Error (' message is wrong ');
// });
Assert.doesnotthrow (function () {
throw new Error ("I lived in the ocean" before Nemo);
// });
Nodejs Assertion Test