Example of use of the Assert assertion library in Nodejs:
Some rules can be found here:
- Equal, NotEqual, deepequal, notdeepequal: compare using the ' = = ' comparison. that is: The method without strict, using the ' = = ' comparison.
- Strictequal, Notstrictequal, strictdeepequal, notstrictdeepequal: compare using the ' = = = ' comparison. that is: A method with strict, using the ' = = = ' comparison.
Describe (' Assert usage test ',function () { varObj1 ={name:' 111 ', Parent: {mother:' 222 ' } } varObj2 ={name:' 111 ', Parent: {mother:' 222 ' } } varObj3 ={name:' 333 ' } varObj4 ={name:333} it (' Assert.ok ',function () { varmsg = ' value should be true 'Assert.ok (true, msg) Assert.ok (' 1 ', msg) Assert.ok (1, MSG)}); It (' Assert.equal ',function() {assert.equal (1, ' 1 ', ' two values should be equal. Use \ ' ==\ ' to compare ')}) it (' Assert.notequal ',function() {assert.notequal (1, 2, ' two values should not be equal. Use \ '!=\ ' to compare ')}) it (' Assert.deepequal ',function() {assert.deepequal (obj1, Obj2,The properties in the ' two objects should be in a depth congruent. Use \ ' ==\ ' to compare ')}) it (' Assert.notdeepequal ',function() {assert.notdeepequal (obj1, Obj3,The attributes in the ' two objects should not be of equal depth. Use \ '!=\ ' to compare ')}) it (' Assert.strictequal ',function () { varmsg = ' Two values should be equal. Use \ ' ===\ ' to compare 'Assert.strictequal (1, 1, msg) assert.strictequal (' 1 ', ' 1 ', msg) assert.strictequal (true,true, msg)}) It (' Assert.notstrictequal ',function () { varmsg = ' Two values should not be equal, or the values are of different types. Use \ '!==\ ' to compare 'Assert.notstrictequal (1, ' 1 ', msg) assert.notstrictequal (1, 2, msg)}) It (' Assert.deepstrictequal ',function() {assert.deepstrictequal (obj1, Obj2,The attributes in the ' two objects should be of equal depth, and the corresponding values are of the same type. Use \ ' ===\ ' to compare ')}) it (' Assert.notdeepstrictequal ',function() {assert.notdeepstrictequal (Obj4, Obj3,The attributes in the ' two objects should not be of equal depth, or the corresponding values are of different types. Use \ '!==\ ' to compare ')}) it (' Assert.throws ',function () { //the corresponding error message should be thrown in the methodAssert.throws (function () { Throw' Error message ' }, /error Messages/)}) it (' Assert.doesnotthrow ',function () { //the corresponding error should not be thrown in the methodAssert.doesnotthrow (function () { varA = 1 + 1; }, Rangeerror,' Throws a rangeerror error ')}) it (' Assert.iferror ',function () { //argument is true, throws an error, and when false, the test passesAssert.iferror (false) }) //it (' Assert.fail ', function () { //assert.fail (1, ' 1 ', ' Active throw error ') // })})
Nodejs-assert Use Example