- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 快速入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 快速入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用工具模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - assert.notDeepEqual() 函式
assert 模組提供了一組斷言函式,用於驗證不變式。Node.js assert.notDeepEqual() 函式是 Node.js assert 模組的內建函式。
Node.js assert.notDeepEqual() 函式 將比較傳入的值是否深度相等。如果值深度相等,則函式將丟擲一個包含訊息引數中文字的 AssertionError。否則,如果值不相等,則不會丟擲任何 AssertionError,也不會返回任何輸出。
此方法與 assert.notDeepStrictEqual() 函式幾乎相同,並且是 assert.deepEqual() 函式的反義。
語法
以下是 Node.js assert.notDeepEqual() 函式 的語法:
assert.notDeepEqual(actual, expected[, message]);
引數
此方法接受三個引數。具體說明如下。
actual − (必需) 此引數中傳遞的值將被評估。值可以是任何型別。
expected − (必需) 此引數中傳遞的值將與 actual 值 進行比較。值可以是任何型別。
message − (可選) 可以將字串或錯誤型別作為輸入傳遞到此引數中。
返回值
如果 actual 和 expected 匹配,則此函式將在終端返回一個 AssertionError。
示例
在下面的示例中,我們將兩個不同的整數值作為 actual 和 expected 傳遞給 Node.js assert.notDeepEqual() 函式,並將文字傳遞給 message 引數。
const assert = require('assert');
var num1 = 34;
var num2 = 45;
assert.notDeepEqual(num1, num2, "Both the numbers are NOT EQUAL");
輸出
當我們編譯並執行程式碼時,該函式不會向輸出丟擲 AssertionError,因為 actual 和 expected 不匹配。
// Returns nothing
示例
在下面的示例中,我們將兩個輸入傳遞給 Node.js assert.notDeepEqual() 函式,一個整數傳遞給 actual 引數,一個字串傳遞給 expected 引數。
const assert = require('assert');
var string1 = '7';
var num1 = 7;
assert.notDeepEqual(string1, num1, "Both the values are EQUAL");
輸出
當我們編譯並執行程式碼時,該函式會向輸出丟擲 AssertionError,因為 7 == '7'。
assert.js:79 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Both the values are EQUAL at Object.<anonymous> (/home/cg/root/639c30a0a5fb2/main.js:6:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19)at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
示例
在下面的示例中,我們建立了兩個具有不同屬性的巢狀物件。然後,我們將這兩個物件作為 actual 和 expected 傳遞給函式,並將文字傳遞給 message 引數。
const assert = require('assert');
var object1 = {
Name : 'Mike',
Id : 17,
Salary : {
"2020-2021" : '45000INR',
"2021-2022" : '50000INR',
},
address: {
Area: {
address1: "White field road",
address2: "Brown wheat field",
},
}
};
var object2 = {
Name : 'Mike',
Id : 17,
Salary : {
"2020-2021" : '45000INR',
"2021-2022" : '50000INR',
},
address: {
Area: {
address1: "White field road",
address2: "Brown wheat field",
},
}
};
assert.notDeepEqual(object1, object2, "Both the objects are EQUAL")
輸出
當我們編譯並執行上述程式時,它會丟擲 AssertionError 和message 到輸出,因為actual 和expected 是相同的。
assert.js:79 throw new AssertionError(obj); ^ AssertionError [ERR_ASSERTION]: Both the objects are EQUAL at Object.<anonymous> (/home/cg/root/639c30a0a5fb2/main.js:33:8) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3) at Function.Module.runMain (internal/modules/cjs/loader.js:744:10) at startup (internal/bootstrap/node.js:238:19) at bootstrapNodeJSCore (internal/bootstrap/node.js:572:3)
示例
在下面的示例中,我們建立了兩個具有相似屬性的巢狀物件。然後,我們將這兩個物件作為 actual 和 expected 傳遞給函式,並將文字傳遞給 message 引數。
const assert = require('assert');
var object1 = {
Name : 'John',
Id : 27,
Salary : {
"2020-2021" : '55000INR',
"2021-2022" : '70000INR',
},
};
var object2 = {
Name : 'Mike',
Id : 17,
Salary : {
"2020-2021" : '45000INR',
"2021-2022" : '50000INR',
},
};
assert.notDeepEqual(object1, object2, "Both the objects are NOT EQUAL");
輸出
因此,當我們編譯並執行程式碼時,該函式不會向輸出丟擲 AssertionError,因為 actual 和 expected 不相同。
// Returns nothing
