node. JS-Assertion

Source: Internet
Author: User

What is an assertion? What does the assertion in the program mean, let's take a question step-by-step exploration

Assertion that we believe that a particular point in the program Boolean expression is True

An example is:

I believe you are right, then let others judge you are right or wrong, and finally I get the result.

Okay, get to the chase.

Assert-ASSERT (the following parameters I will not introduce, directly on code)

1 assert (value[, message])2 assert (Value,meesage)3 //The two formats are the same, the ' [] ' in the program represents an optional section, ' <> ' stands for the required part. 4 5 Assert.deepequal (Actual, expected[, message])
6 Assert.deepstrictequal (Actual, expected[, message])
7 Assert.doesnotthrow (block[, error][, message])
8 Assert.equal (Actual, expected[, message])
9 assert.fail (message)
Ten Assert.fail (Actual, expected[, message[, operator[, Stackstartfunction]])
One Assert.iferror (value)
A Assert.notdeepequal (Actual, expected[, message])
- Assert.notdeepstrictequal (Actual, expected[, message])
- Assert.notequal (Actual, expected[, message])
the Assert.notstrictequal (Actual, expected[, message])
- Assert.ok (value[, message])
- Assert.strictequal (Actual, expected[, message])
-Assert.throws (block[, error][, message])

ASSERT (value[, message])
Const ASSERT = require (' assert '); ASSERT (true, Console.log (' * * * print out information) ");

Assert.deepequal (Actual, expected[, message])

Tests only the enumerable properties of itself, without testing the object's prototype, connector, or non-enumerable properties (these cases are used assert.deepStrictEqual() ). For example, the following example is not thrown AssertionError because RegExp the object's properties are not enumerable:

Prototype: the original type

Connector: "+"

Enumerable self-Properties:

Console.log (Object.keys (var_name))

Enumerable self-properties of the output

Non-enumerable properties: The comparison point for enumerable and non-enumerated types is: Can it be used for. In traversal to

var New Number ();  for (var in num) {     
Console.log ("Num." + Pro + "=" + Num[pro]);}

//fortest.js

//non-enumerable JS base type, return nullvarnum =NewNumber (); for(varProinchnum) {Console.log ("Num." + Pro + "=" +Num[pro]);}functionPerson () { This. Name = "KXY";} Person.prototype={constructor:person, job:"Student",};varKxy =NewPerson (); Object.defineproperty (Kxy,"Sex", {value:"Female", Enumerable:false});//non-enumerable sex, mainly because of enumerable (true enumeration) for(varProinchkxy) {Console.log ("Kxy." + Pro + "=" +Kxy[pro]);}//enumerable self-PropertiesConsole.log (Object.keys (KXY));

node. JS-Assertion

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.