Nodejs-assert Use Example

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.