11cb0ef41Sopenharmony_ci{ 21cb0ef41Sopenharmony_ci "type": "module", 31cb0ef41Sopenharmony_ci "source": "doc/api/assert.md", 41cb0ef41Sopenharmony_ci "modules": [ 51cb0ef41Sopenharmony_ci { 61cb0ef41Sopenharmony_ci "textRaw": "Assert", 71cb0ef41Sopenharmony_ci "name": "assert", 81cb0ef41Sopenharmony_ci "introduced_in": "v0.1.21", 91cb0ef41Sopenharmony_ci "stability": 2, 101cb0ef41Sopenharmony_ci "stabilityText": "Stable", 111cb0ef41Sopenharmony_ci "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v18.20.1/lib/assert.js\">lib/assert.js</a></p>\n<p>The <code>node:assert</code> module provides a set of assertion functions for verifying\ninvariants.</p>", 121cb0ef41Sopenharmony_ci "modules": [ 131cb0ef41Sopenharmony_ci { 141cb0ef41Sopenharmony_ci "textRaw": "Strict assertion mode", 151cb0ef41Sopenharmony_ci "name": "strict_assertion_mode", 161cb0ef41Sopenharmony_ci "meta": { 171cb0ef41Sopenharmony_ci "added": [ 181cb0ef41Sopenharmony_ci "v9.9.0" 191cb0ef41Sopenharmony_ci ], 201cb0ef41Sopenharmony_ci "changes": [ 211cb0ef41Sopenharmony_ci { 221cb0ef41Sopenharmony_ci "version": "v15.0.0", 231cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/34001", 241cb0ef41Sopenharmony_ci "description": "Exposed as `require('node:assert/strict')`." 251cb0ef41Sopenharmony_ci }, 261cb0ef41Sopenharmony_ci { 271cb0ef41Sopenharmony_ci "version": [ 281cb0ef41Sopenharmony_ci "v13.9.0", 291cb0ef41Sopenharmony_ci "v12.16.2" 301cb0ef41Sopenharmony_ci ], 311cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/31635", 321cb0ef41Sopenharmony_ci "description": "Changed \"strict mode\" to \"strict assertion mode\" and \"legacy mode\" to \"legacy assertion mode\" to avoid confusion with the more usual meaning of \"strict mode\"." 331cb0ef41Sopenharmony_ci }, 341cb0ef41Sopenharmony_ci { 351cb0ef41Sopenharmony_ci "version": "v9.9.0", 361cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/17615", 371cb0ef41Sopenharmony_ci "description": "Added error diffs to the strict assertion mode." 381cb0ef41Sopenharmony_ci }, 391cb0ef41Sopenharmony_ci { 401cb0ef41Sopenharmony_ci "version": "v9.9.0", 411cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/17002", 421cb0ef41Sopenharmony_ci "description": "Added strict assertion mode to the assert module." 431cb0ef41Sopenharmony_ci } 441cb0ef41Sopenharmony_ci ] 451cb0ef41Sopenharmony_ci }, 461cb0ef41Sopenharmony_ci "desc": "<p>In strict assertion mode, non-strict methods behave like their corresponding\nstrict methods. For example, <a href=\"#assertdeepequalactual-expected-message\"><code>assert.deepEqual()</code></a> will behave like\n<a href=\"#assertdeepstrictequalactual-expected-message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<p>In strict assertion mode, error messages for objects display a diff. In legacy\nassertion mode, error messages for objects display the objects, often truncated.</p>\n<p>To use strict assertion mode:</p>\n<pre><code class=\"language-mjs\">import { strict as assert } from 'node:assert';\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert').strict;\n</code></pre>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n</code></pre>\n<p>Example error diff:</p>\n<pre><code class=\"language-mjs\">import { strict as assert } from 'node:assert';\n\nassert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected ... Lines skipped\n//\n// [\n// [\n// ...\n// 2,\n// + 3\n// - '3'\n// ],\n// ...\n// 5\n// ]\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected ... Lines skipped\n//\n// [\n// [\n// ...\n// 2,\n// + 3\n// - '3'\n// ],\n// ...\n// 5\n// ]\n</code></pre>\n<p>To deactivate the colors, use the <code>NO_COLOR</code> or <code>NODE_DISABLE_COLORS</code>\nenvironment variables. This will also deactivate the colors in the REPL. For\nmore on color support in terminal environments, read the tty\n<a href=\"tty.html#writestreamgetcolordepthenv\"><code>getColorDepth()</code></a> documentation.</p>", 471cb0ef41Sopenharmony_ci "type": "module", 481cb0ef41Sopenharmony_ci "displayName": "Strict assertion mode" 491cb0ef41Sopenharmony_ci }, 501cb0ef41Sopenharmony_ci { 511cb0ef41Sopenharmony_ci "textRaw": "Legacy assertion mode", 521cb0ef41Sopenharmony_ci "name": "legacy_assertion_mode", 531cb0ef41Sopenharmony_ci "desc": "<p>Legacy assertion mode uses the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\"><code>==</code> operator</a> in:</p>\n<ul>\n<li><a href=\"#assertdeepequalactual-expected-message\"><code>assert.deepEqual()</code></a></li>\n<li><a href=\"#assertequalactual-expected-message\"><code>assert.equal()</code></a></li>\n<li><a href=\"#assertnotdeepequalactual-expected-message\"><code>assert.notDeepEqual()</code></a></li>\n<li><a href=\"#assertnotequalactual-expected-message\"><code>assert.notEqual()</code></a></li>\n</ul>\n<p>To use legacy assertion mode:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n</code></pre>\n<p>Legacy assertion mode may have surprising results, especially when using\n<a href=\"#assertdeepequalactual-expected-message\"><code>assert.deepEqual()</code></a>:</p>\n<pre><code class=\"language-cjs\">// WARNING: This does not throw an AssertionError in legacy assertion mode!\nassert.deepEqual(/a/gi, new Date());\n</code></pre>", 541cb0ef41Sopenharmony_ci "type": "module", 551cb0ef41Sopenharmony_ci "displayName": "Legacy assertion mode" 561cb0ef41Sopenharmony_ci } 571cb0ef41Sopenharmony_ci ], 581cb0ef41Sopenharmony_ci "classes": [ 591cb0ef41Sopenharmony_ci { 601cb0ef41Sopenharmony_ci "textRaw": "Class: assert.AssertionError", 611cb0ef41Sopenharmony_ci "type": "class", 621cb0ef41Sopenharmony_ci "name": "assert.AssertionError", 631cb0ef41Sopenharmony_ci "desc": "<ul>\n<li>Extends: <a href=\"errors.html#class-error\" class=\"type\"><errors.Error></a></li>\n</ul>\n<p>Indicates the failure of an assertion. All errors thrown by the <code>node:assert</code>\nmodule will be instances of the <code>AssertionError</code> class.</p>", 641cb0ef41Sopenharmony_ci "signatures": [ 651cb0ef41Sopenharmony_ci { 661cb0ef41Sopenharmony_ci "params": [ 671cb0ef41Sopenharmony_ci { 681cb0ef41Sopenharmony_ci "textRaw": "`options` {Object}", 691cb0ef41Sopenharmony_ci "name": "options", 701cb0ef41Sopenharmony_ci "type": "Object", 711cb0ef41Sopenharmony_ci "options": [ 721cb0ef41Sopenharmony_ci { 731cb0ef41Sopenharmony_ci "textRaw": "`message` {string} If provided, the error message is set to this value.", 741cb0ef41Sopenharmony_ci "name": "message", 751cb0ef41Sopenharmony_ci "type": "string", 761cb0ef41Sopenharmony_ci "desc": "If provided, the error message is set to this value." 771cb0ef41Sopenharmony_ci }, 781cb0ef41Sopenharmony_ci { 791cb0ef41Sopenharmony_ci "textRaw": "`actual` {any} The `actual` property on the error instance.", 801cb0ef41Sopenharmony_ci "name": "actual", 811cb0ef41Sopenharmony_ci "type": "any", 821cb0ef41Sopenharmony_ci "desc": "The `actual` property on the error instance." 831cb0ef41Sopenharmony_ci }, 841cb0ef41Sopenharmony_ci { 851cb0ef41Sopenharmony_ci "textRaw": "`expected` {any} The `expected` property on the error instance.", 861cb0ef41Sopenharmony_ci "name": "expected", 871cb0ef41Sopenharmony_ci "type": "any", 881cb0ef41Sopenharmony_ci "desc": "The `expected` property on the error instance." 891cb0ef41Sopenharmony_ci }, 901cb0ef41Sopenharmony_ci { 911cb0ef41Sopenharmony_ci "textRaw": "`operator` {string} The `operator` property on the error instance.", 921cb0ef41Sopenharmony_ci "name": "operator", 931cb0ef41Sopenharmony_ci "type": "string", 941cb0ef41Sopenharmony_ci "desc": "The `operator` property on the error instance." 951cb0ef41Sopenharmony_ci }, 961cb0ef41Sopenharmony_ci { 971cb0ef41Sopenharmony_ci "textRaw": "`stackStartFn` {Function} If provided, the generated stack trace omits frames before this function.", 981cb0ef41Sopenharmony_ci "name": "stackStartFn", 991cb0ef41Sopenharmony_ci "type": "Function", 1001cb0ef41Sopenharmony_ci "desc": "If provided, the generated stack trace omits frames before this function." 1011cb0ef41Sopenharmony_ci } 1021cb0ef41Sopenharmony_ci ] 1031cb0ef41Sopenharmony_ci } 1041cb0ef41Sopenharmony_ci ], 1051cb0ef41Sopenharmony_ci "desc": "<p>A subclass of <code>Error</code> that indicates the failure of an assertion.</p>\n<p>All instances contain the built-in <code>Error</code> properties (<code>message</code> and <code>name</code>)\nand:</p>\n<ul>\n<li><code>actual</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\"><any></a> Set to the <code>actual</code> argument for methods such as\n<a href=\"#assertstrictequalactual-expected-message\"><code>assert.strictEqual()</code></a>.</li>\n<li><code>expected</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types\" class=\"type\"><any></a> Set to the <code>expected</code> value for methods such as\n<a href=\"#assertstrictequalactual-expected-message\"><code>assert.strictEqual()</code></a>.</li>\n<li><code>generatedMessage</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Boolean_type\" class=\"type\"><boolean></a> Indicates if the message was auto-generated\n(<code>true</code>) or not.</li>\n<li><code>code</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> Value is always <code>ERR_ASSERTION</code> to show that the error is an\nassertion error.</li>\n<li><code>operator</code> <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type\" class=\"type\"><string></a> Set to the passed in operator value.</li>\n</ul>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\n// Generate an AssertionError to compare the error message later:\nconst { message } = new assert.AssertionError({\n actual: 1,\n expected: 2,\n operator: 'strictEqual',\n});\n\n// Verify error output:\ntry {\n assert.strictEqual(1, 2);\n} catch (err) {\n assert(err instanceof assert.AssertionError);\n assert.strictEqual(err.message, message);\n assert.strictEqual(err.name, 'AssertionError');\n assert.strictEqual(err.actual, 1);\n assert.strictEqual(err.expected, 2);\n assert.strictEqual(err.code, 'ERR_ASSERTION');\n assert.strictEqual(err.operator, 'strictEqual');\n assert.strictEqual(err.generatedMessage, true);\n}\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Generate an AssertionError to compare the error message later:\nconst { message } = new assert.AssertionError({\n actual: 1,\n expected: 2,\n operator: 'strictEqual',\n});\n\n// Verify error output:\ntry {\n assert.strictEqual(1, 2);\n} catch (err) {\n assert(err instanceof assert.AssertionError);\n assert.strictEqual(err.message, message);\n assert.strictEqual(err.name, 'AssertionError');\n assert.strictEqual(err.actual, 1);\n assert.strictEqual(err.expected, 2);\n assert.strictEqual(err.code, 'ERR_ASSERTION');\n assert.strictEqual(err.operator, 'strictEqual');\n assert.strictEqual(err.generatedMessage, true);\n}\n</code></pre>" 1061cb0ef41Sopenharmony_ci } 1071cb0ef41Sopenharmony_ci ] 1081cb0ef41Sopenharmony_ci }, 1091cb0ef41Sopenharmony_ci { 1101cb0ef41Sopenharmony_ci "textRaw": "Class: `assert.CallTracker`", 1111cb0ef41Sopenharmony_ci "type": "class", 1121cb0ef41Sopenharmony_ci "name": "assert.CallTracker", 1131cb0ef41Sopenharmony_ci "meta": { 1141cb0ef41Sopenharmony_ci "added": [ 1151cb0ef41Sopenharmony_ci "v14.2.0", 1161cb0ef41Sopenharmony_ci "v12.19.0" 1171cb0ef41Sopenharmony_ci ], 1181cb0ef41Sopenharmony_ci "changes": [] 1191cb0ef41Sopenharmony_ci }, 1201cb0ef41Sopenharmony_ci "stability": 1, 1211cb0ef41Sopenharmony_ci "stabilityText": "Experimental", 1221cb0ef41Sopenharmony_ci "desc": "<p>This feature is currently experimental and behavior might still change.</p>", 1231cb0ef41Sopenharmony_ci "methods": [ 1241cb0ef41Sopenharmony_ci { 1251cb0ef41Sopenharmony_ci "textRaw": "`tracker.calls([fn][, exact])`", 1261cb0ef41Sopenharmony_ci "type": "method", 1271cb0ef41Sopenharmony_ci "name": "calls", 1281cb0ef41Sopenharmony_ci "meta": { 1291cb0ef41Sopenharmony_ci "added": [ 1301cb0ef41Sopenharmony_ci "v14.2.0", 1311cb0ef41Sopenharmony_ci "v12.19.0" 1321cb0ef41Sopenharmony_ci ], 1331cb0ef41Sopenharmony_ci "changes": [] 1341cb0ef41Sopenharmony_ci }, 1351cb0ef41Sopenharmony_ci "signatures": [ 1361cb0ef41Sopenharmony_ci { 1371cb0ef41Sopenharmony_ci "return": { 1381cb0ef41Sopenharmony_ci "textRaw": "Returns: {Function} that wraps `fn`.", 1391cb0ef41Sopenharmony_ci "name": "return", 1401cb0ef41Sopenharmony_ci "type": "Function", 1411cb0ef41Sopenharmony_ci "desc": "that wraps `fn`." 1421cb0ef41Sopenharmony_ci }, 1431cb0ef41Sopenharmony_ci "params": [ 1441cb0ef41Sopenharmony_ci { 1451cb0ef41Sopenharmony_ci "textRaw": "`fn` {Function} **Default:** A no-op function.", 1461cb0ef41Sopenharmony_ci "name": "fn", 1471cb0ef41Sopenharmony_ci "type": "Function", 1481cb0ef41Sopenharmony_ci "default": "A no-op function" 1491cb0ef41Sopenharmony_ci }, 1501cb0ef41Sopenharmony_ci { 1511cb0ef41Sopenharmony_ci "textRaw": "`exact` {number} **Default:** `1`.", 1521cb0ef41Sopenharmony_ci "name": "exact", 1531cb0ef41Sopenharmony_ci "type": "number", 1541cb0ef41Sopenharmony_ci "default": "`1`" 1551cb0ef41Sopenharmony_ci } 1561cb0ef41Sopenharmony_ci ] 1571cb0ef41Sopenharmony_ci } 1581cb0ef41Sopenharmony_ci ], 1591cb0ef41Sopenharmony_ci "desc": "<p>The wrapper function is expected to be called exactly <code>exact</code> times. If the\nfunction has not been called exactly <code>exact</code> times when\n<a href=\"#trackerverify\"><code>tracker.verify()</code></a> is called, then <a href=\"#trackerverify\"><code>tracker.verify()</code></a> will throw an\nerror.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func);\n</code></pre>" 1601cb0ef41Sopenharmony_ci }, 1611cb0ef41Sopenharmony_ci { 1621cb0ef41Sopenharmony_ci "textRaw": "`tracker.getCalls(fn)`", 1631cb0ef41Sopenharmony_ci "type": "method", 1641cb0ef41Sopenharmony_ci "name": "getCalls", 1651cb0ef41Sopenharmony_ci "meta": { 1661cb0ef41Sopenharmony_ci "added": [ 1671cb0ef41Sopenharmony_ci "v18.8.0" 1681cb0ef41Sopenharmony_ci ], 1691cb0ef41Sopenharmony_ci "changes": [] 1701cb0ef41Sopenharmony_ci }, 1711cb0ef41Sopenharmony_ci "signatures": [ 1721cb0ef41Sopenharmony_ci { 1731cb0ef41Sopenharmony_ci "return": { 1741cb0ef41Sopenharmony_ci "textRaw": "Returns: {Array} with all the calls to a tracked function.", 1751cb0ef41Sopenharmony_ci "name": "return", 1761cb0ef41Sopenharmony_ci "type": "Array", 1771cb0ef41Sopenharmony_ci "desc": "with all the calls to a tracked function." 1781cb0ef41Sopenharmony_ci }, 1791cb0ef41Sopenharmony_ci "params": [ 1801cb0ef41Sopenharmony_ci { 1811cb0ef41Sopenharmony_ci "textRaw": "`fn` {Function}.", 1821cb0ef41Sopenharmony_ci "name": "fn", 1831cb0ef41Sopenharmony_ci "type": "Function", 1841cb0ef41Sopenharmony_ci "desc": "." 1851cb0ef41Sopenharmony_ci }, 1861cb0ef41Sopenharmony_ci { 1871cb0ef41Sopenharmony_ci "textRaw": "Object {Object}", 1881cb0ef41Sopenharmony_ci "name": "Object", 1891cb0ef41Sopenharmony_ci "type": "Object", 1901cb0ef41Sopenharmony_ci "options": [ 1911cb0ef41Sopenharmony_ci { 1921cb0ef41Sopenharmony_ci "textRaw": "`thisArg` {Object}", 1931cb0ef41Sopenharmony_ci "name": "thisArg", 1941cb0ef41Sopenharmony_ci "type": "Object" 1951cb0ef41Sopenharmony_ci }, 1961cb0ef41Sopenharmony_ci { 1971cb0ef41Sopenharmony_ci "textRaw": "`arguments` {Array} the arguments passed to the tracked function", 1981cb0ef41Sopenharmony_ci "name": "arguments", 1991cb0ef41Sopenharmony_ci "type": "Array", 2001cb0ef41Sopenharmony_ci "desc": "the arguments passed to the tracked function" 2011cb0ef41Sopenharmony_ci } 2021cb0ef41Sopenharmony_ci ] 2031cb0ef41Sopenharmony_ci } 2041cb0ef41Sopenharmony_ci ] 2051cb0ef41Sopenharmony_ci } 2061cb0ef41Sopenharmony_ci ], 2071cb0ef41Sopenharmony_ci "desc": "<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\nconst callsfunc = tracker.calls(func);\ncallsfunc(1, 2, 3);\n\nassert.deepStrictEqual(tracker.getCalls(callsfunc),\n [{ thisArg: undefined, arguments: [1, 2, 3] }]);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\nconst callsfunc = tracker.calls(func);\ncallsfunc(1, 2, 3);\n\nassert.deepStrictEqual(tracker.getCalls(callsfunc),\n [{ thisArg: undefined, arguments: [1, 2, 3] }]);\n</code></pre>" 2081cb0ef41Sopenharmony_ci }, 2091cb0ef41Sopenharmony_ci { 2101cb0ef41Sopenharmony_ci "textRaw": "`tracker.report()`", 2111cb0ef41Sopenharmony_ci "type": "method", 2121cb0ef41Sopenharmony_ci "name": "report", 2131cb0ef41Sopenharmony_ci "meta": { 2141cb0ef41Sopenharmony_ci "added": [ 2151cb0ef41Sopenharmony_ci "v14.2.0", 2161cb0ef41Sopenharmony_ci "v12.19.0" 2171cb0ef41Sopenharmony_ci ], 2181cb0ef41Sopenharmony_ci "changes": [] 2191cb0ef41Sopenharmony_ci }, 2201cb0ef41Sopenharmony_ci "signatures": [ 2211cb0ef41Sopenharmony_ci { 2221cb0ef41Sopenharmony_ci "return": { 2231cb0ef41Sopenharmony_ci "textRaw": "Returns: {Array} of objects containing information about the wrapper functions returned by [`tracker.calls()`][].", 2241cb0ef41Sopenharmony_ci "name": "return", 2251cb0ef41Sopenharmony_ci "type": "Array", 2261cb0ef41Sopenharmony_ci "desc": "of objects containing information about the wrapper functions returned by [`tracker.calls()`][]." 2271cb0ef41Sopenharmony_ci }, 2281cb0ef41Sopenharmony_ci "params": [ 2291cb0ef41Sopenharmony_ci { 2301cb0ef41Sopenharmony_ci "textRaw": "Object {Object}", 2311cb0ef41Sopenharmony_ci "name": "Object", 2321cb0ef41Sopenharmony_ci "type": "Object", 2331cb0ef41Sopenharmony_ci "options": [ 2341cb0ef41Sopenharmony_ci { 2351cb0ef41Sopenharmony_ci "textRaw": "`message` {string}", 2361cb0ef41Sopenharmony_ci "name": "message", 2371cb0ef41Sopenharmony_ci "type": "string" 2381cb0ef41Sopenharmony_ci }, 2391cb0ef41Sopenharmony_ci { 2401cb0ef41Sopenharmony_ci "textRaw": "`actual` {number} The actual number of times the function was called.", 2411cb0ef41Sopenharmony_ci "name": "actual", 2421cb0ef41Sopenharmony_ci "type": "number", 2431cb0ef41Sopenharmony_ci "desc": "The actual number of times the function was called." 2441cb0ef41Sopenharmony_ci }, 2451cb0ef41Sopenharmony_ci { 2461cb0ef41Sopenharmony_ci "textRaw": "`expected` {number} The number of times the function was expected to be called.", 2471cb0ef41Sopenharmony_ci "name": "expected", 2481cb0ef41Sopenharmony_ci "type": "number", 2491cb0ef41Sopenharmony_ci "desc": "The number of times the function was expected to be called." 2501cb0ef41Sopenharmony_ci }, 2511cb0ef41Sopenharmony_ci { 2521cb0ef41Sopenharmony_ci "textRaw": "`operator` {string} The name of the function that is wrapped.", 2531cb0ef41Sopenharmony_ci "name": "operator", 2541cb0ef41Sopenharmony_ci "type": "string", 2551cb0ef41Sopenharmony_ci "desc": "The name of the function that is wrapped." 2561cb0ef41Sopenharmony_ci }, 2571cb0ef41Sopenharmony_ci { 2581cb0ef41Sopenharmony_ci "textRaw": "`stack` {Object} A stack trace of the function.", 2591cb0ef41Sopenharmony_ci "name": "stack", 2601cb0ef41Sopenharmony_ci "type": "Object", 2611cb0ef41Sopenharmony_ci "desc": "A stack trace of the function." 2621cb0ef41Sopenharmony_ci } 2631cb0ef41Sopenharmony_ci ] 2641cb0ef41Sopenharmony_ci } 2651cb0ef41Sopenharmony_ci ] 2661cb0ef41Sopenharmony_ci } 2671cb0ef41Sopenharmony_ci ], 2681cb0ef41Sopenharmony_ci "desc": "<p>The arrays contains information about the expected and actual number of calls of\nthe functions that have not been called the expected number of times.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func, 2);\n\n// Returns an array containing information on callsfunc()\nconsole.log(tracker.report());\n// [\n// {\n// message: 'Expected the func function to be executed 2 time(s) but was\n// executed 0 time(s).',\n// actual: 0,\n// expected: 2,\n// operator: 'func',\n// stack: stack trace\n// }\n// ]\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func, 2);\n\n// Returns an array containing information on callsfunc()\nconsole.log(tracker.report());\n// [\n// {\n// message: 'Expected the func function to be executed 2 time(s) but was\n// executed 0 time(s).',\n// actual: 0,\n// expected: 2,\n// operator: 'func',\n// stack: stack trace\n// }\n// ]\n</code></pre>" 2691cb0ef41Sopenharmony_ci }, 2701cb0ef41Sopenharmony_ci { 2711cb0ef41Sopenharmony_ci "textRaw": "`tracker.reset([fn])`", 2721cb0ef41Sopenharmony_ci "type": "method", 2731cb0ef41Sopenharmony_ci "name": "reset", 2741cb0ef41Sopenharmony_ci "meta": { 2751cb0ef41Sopenharmony_ci "added": [ 2761cb0ef41Sopenharmony_ci "v18.8.0" 2771cb0ef41Sopenharmony_ci ], 2781cb0ef41Sopenharmony_ci "changes": [] 2791cb0ef41Sopenharmony_ci }, 2801cb0ef41Sopenharmony_ci "signatures": [ 2811cb0ef41Sopenharmony_ci { 2821cb0ef41Sopenharmony_ci "params": [ 2831cb0ef41Sopenharmony_ci { 2841cb0ef41Sopenharmony_ci "textRaw": "`fn` {Function} a tracked function to reset.", 2851cb0ef41Sopenharmony_ci "name": "fn", 2861cb0ef41Sopenharmony_ci "type": "Function", 2871cb0ef41Sopenharmony_ci "desc": "a tracked function to reset." 2881cb0ef41Sopenharmony_ci } 2891cb0ef41Sopenharmony_ci ] 2901cb0ef41Sopenharmony_ci } 2911cb0ef41Sopenharmony_ci ], 2921cb0ef41Sopenharmony_ci "desc": "<p>Reset calls of the call tracker.\nIf a tracked function is passed as an argument, the calls will be reset for it.\nIf no arguments are passed, all tracked functions will be reset</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\nconst callsfunc = tracker.calls(func);\n\ncallsfunc();\n// Tracker was called once\nassert.strictEqual(tracker.getCalls(callsfunc).length, 1);\n\ntracker.reset(callsfunc);\nassert.strictEqual(tracker.getCalls(callsfunc).length, 0);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\nconst callsfunc = tracker.calls(func);\n\ncallsfunc();\n// Tracker was called once\nassert.strictEqual(tracker.getCalls(callsfunc).length, 1);\n\ntracker.reset(callsfunc);\nassert.strictEqual(tracker.getCalls(callsfunc).length, 0);\n</code></pre>" 2931cb0ef41Sopenharmony_ci }, 2941cb0ef41Sopenharmony_ci { 2951cb0ef41Sopenharmony_ci "textRaw": "`tracker.verify()`", 2961cb0ef41Sopenharmony_ci "type": "method", 2971cb0ef41Sopenharmony_ci "name": "verify", 2981cb0ef41Sopenharmony_ci "meta": { 2991cb0ef41Sopenharmony_ci "added": [ 3001cb0ef41Sopenharmony_ci "v14.2.0", 3011cb0ef41Sopenharmony_ci "v12.19.0" 3021cb0ef41Sopenharmony_ci ], 3031cb0ef41Sopenharmony_ci "changes": [] 3041cb0ef41Sopenharmony_ci }, 3051cb0ef41Sopenharmony_ci "signatures": [ 3061cb0ef41Sopenharmony_ci { 3071cb0ef41Sopenharmony_ci "params": [] 3081cb0ef41Sopenharmony_ci } 3091cb0ef41Sopenharmony_ci ], 3101cb0ef41Sopenharmony_ci "desc": "<p>Iterates through the list of functions passed to\n<a href=\"#trackercallsfn-exact\"><code>tracker.calls()</code></a> and will throw an error for functions that\nhave not been called the expected number of times.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func, 2);\n\ncallsfunc();\n\n// Will throw an error since callsfunc() was only called once.\ntracker.verify();\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Creates call tracker.\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// Returns a function that wraps func() that must be called exact times\n// before tracker.verify().\nconst callsfunc = tracker.calls(func, 2);\n\ncallsfunc();\n\n// Will throw an error since callsfunc() was only called once.\ntracker.verify();\n</code></pre>" 3111cb0ef41Sopenharmony_ci } 3121cb0ef41Sopenharmony_ci ], 3131cb0ef41Sopenharmony_ci "signatures": [ 3141cb0ef41Sopenharmony_ci { 3151cb0ef41Sopenharmony_ci "params": [], 3161cb0ef41Sopenharmony_ci "desc": "<p>Creates a new <a href=\"#class-assertcalltracker\"><code>CallTracker</code></a> object which can be used to track if functions\nwere called a specific number of times. The <code>tracker.verify()</code> must be called\nfor the verification to take place. The usual pattern would be to call it in a\n<a href=\"process.html#event-exit\"><code>process.on('exit')</code></a> handler.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\nimport process from 'node:process';\n\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// callsfunc() must be called exactly 1 time before tracker.verify().\nconst callsfunc = tracker.calls(func, 1);\n\ncallsfunc();\n\n// Calls tracker.verify() and verifies if all tracker.calls() functions have\n// been called exact times.\nprocess.on('exit', () => {\n tracker.verify();\n});\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nconst tracker = new assert.CallTracker();\n\nfunction func() {}\n\n// callsfunc() must be called exactly 1 time before tracker.verify().\nconst callsfunc = tracker.calls(func, 1);\n\ncallsfunc();\n\n// Calls tracker.verify() and verifies if all tracker.calls() functions have\n// been called exact times.\nprocess.on('exit', () => {\n tracker.verify();\n});\n</code></pre>" 3171cb0ef41Sopenharmony_ci } 3181cb0ef41Sopenharmony_ci ] 3191cb0ef41Sopenharmony_ci } 3201cb0ef41Sopenharmony_ci ], 3211cb0ef41Sopenharmony_ci "methods": [ 3221cb0ef41Sopenharmony_ci { 3231cb0ef41Sopenharmony_ci "textRaw": "`assert(value[, message])`", 3241cb0ef41Sopenharmony_ci "type": "method", 3251cb0ef41Sopenharmony_ci "name": "assert", 3261cb0ef41Sopenharmony_ci "meta": { 3271cb0ef41Sopenharmony_ci "added": [ 3281cb0ef41Sopenharmony_ci "v0.5.9" 3291cb0ef41Sopenharmony_ci ], 3301cb0ef41Sopenharmony_ci "changes": [] 3311cb0ef41Sopenharmony_ci }, 3321cb0ef41Sopenharmony_ci "signatures": [ 3331cb0ef41Sopenharmony_ci { 3341cb0ef41Sopenharmony_ci "params": [ 3351cb0ef41Sopenharmony_ci { 3361cb0ef41Sopenharmony_ci "textRaw": "`value` {any} The input that is checked for being truthy.", 3371cb0ef41Sopenharmony_ci "name": "value", 3381cb0ef41Sopenharmony_ci "type": "any", 3391cb0ef41Sopenharmony_ci "desc": "The input that is checked for being truthy." 3401cb0ef41Sopenharmony_ci }, 3411cb0ef41Sopenharmony_ci { 3421cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 3431cb0ef41Sopenharmony_ci "name": "message", 3441cb0ef41Sopenharmony_ci "type": "string|Error" 3451cb0ef41Sopenharmony_ci } 3461cb0ef41Sopenharmony_ci ] 3471cb0ef41Sopenharmony_ci } 3481cb0ef41Sopenharmony_ci ], 3491cb0ef41Sopenharmony_ci "desc": "<p>An alias of <a href=\"#assertokvalue-message\"><code>assert.ok()</code></a>.</p>" 3501cb0ef41Sopenharmony_ci }, 3511cb0ef41Sopenharmony_ci { 3521cb0ef41Sopenharmony_ci "textRaw": "`assert.deepEqual(actual, expected[, message])`", 3531cb0ef41Sopenharmony_ci "type": "method", 3541cb0ef41Sopenharmony_ci "name": "deepEqual", 3551cb0ef41Sopenharmony_ci "meta": { 3561cb0ef41Sopenharmony_ci "added": [ 3571cb0ef41Sopenharmony_ci "v0.1.21" 3581cb0ef41Sopenharmony_ci ], 3591cb0ef41Sopenharmony_ci "changes": [ 3601cb0ef41Sopenharmony_ci { 3611cb0ef41Sopenharmony_ci "version": "v18.0.0", 3621cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/41020", 3631cb0ef41Sopenharmony_ci "description": "Regular expressions lastIndex property is now compared as well." 3641cb0ef41Sopenharmony_ci }, 3651cb0ef41Sopenharmony_ci { 3661cb0ef41Sopenharmony_ci "version": [ 3671cb0ef41Sopenharmony_ci "v16.0.0", 3681cb0ef41Sopenharmony_ci "v14.18.0" 3691cb0ef41Sopenharmony_ci ], 3701cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38113", 3711cb0ef41Sopenharmony_ci "description": "In Legacy assertion mode, changed status from Deprecated to Legacy." 3721cb0ef41Sopenharmony_ci }, 3731cb0ef41Sopenharmony_ci { 3741cb0ef41Sopenharmony_ci "version": "v14.0.0", 3751cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/30766", 3761cb0ef41Sopenharmony_ci "description": "NaN is now treated as being identical if both sides are NaN." 3771cb0ef41Sopenharmony_ci }, 3781cb0ef41Sopenharmony_ci { 3791cb0ef41Sopenharmony_ci "version": "v12.0.0", 3801cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/25008", 3811cb0ef41Sopenharmony_ci "description": "The type tags are now properly compared and there are a couple minor comparison adjustments to make the check less surprising." 3821cb0ef41Sopenharmony_ci }, 3831cb0ef41Sopenharmony_ci { 3841cb0ef41Sopenharmony_ci "version": "v9.0.0", 3851cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15001", 3861cb0ef41Sopenharmony_ci "description": "The `Error` names and messages are now properly compared." 3871cb0ef41Sopenharmony_ci }, 3881cb0ef41Sopenharmony_ci { 3891cb0ef41Sopenharmony_ci "version": "v8.0.0", 3901cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/12142", 3911cb0ef41Sopenharmony_ci "description": "The `Set` and `Map` content is also compared." 3921cb0ef41Sopenharmony_ci }, 3931cb0ef41Sopenharmony_ci { 3941cb0ef41Sopenharmony_ci "version": [ 3951cb0ef41Sopenharmony_ci "v6.4.0", 3961cb0ef41Sopenharmony_ci "v4.7.1" 3971cb0ef41Sopenharmony_ci ], 3981cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/8002", 3991cb0ef41Sopenharmony_ci "description": "Typed array slices are handled correctly now." 4001cb0ef41Sopenharmony_ci }, 4011cb0ef41Sopenharmony_ci { 4021cb0ef41Sopenharmony_ci "version": [ 4031cb0ef41Sopenharmony_ci "v6.1.0", 4041cb0ef41Sopenharmony_ci "v4.5.0" 4051cb0ef41Sopenharmony_ci ], 4061cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6432", 4071cb0ef41Sopenharmony_ci "description": "Objects with circular references can be used as inputs now." 4081cb0ef41Sopenharmony_ci }, 4091cb0ef41Sopenharmony_ci { 4101cb0ef41Sopenharmony_ci "version": [ 4111cb0ef41Sopenharmony_ci "v5.10.1", 4121cb0ef41Sopenharmony_ci "v4.4.3" 4131cb0ef41Sopenharmony_ci ], 4141cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/5910", 4151cb0ef41Sopenharmony_ci "description": "Handle non-`Uint8Array` typed arrays correctly." 4161cb0ef41Sopenharmony_ci } 4171cb0ef41Sopenharmony_ci ] 4181cb0ef41Sopenharmony_ci }, 4191cb0ef41Sopenharmony_ci "signatures": [ 4201cb0ef41Sopenharmony_ci { 4211cb0ef41Sopenharmony_ci "params": [ 4221cb0ef41Sopenharmony_ci { 4231cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 4241cb0ef41Sopenharmony_ci "name": "actual", 4251cb0ef41Sopenharmony_ci "type": "any" 4261cb0ef41Sopenharmony_ci }, 4271cb0ef41Sopenharmony_ci { 4281cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 4291cb0ef41Sopenharmony_ci "name": "expected", 4301cb0ef41Sopenharmony_ci "type": "any" 4311cb0ef41Sopenharmony_ci }, 4321cb0ef41Sopenharmony_ci { 4331cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 4341cb0ef41Sopenharmony_ci "name": "message", 4351cb0ef41Sopenharmony_ci "type": "string|Error" 4361cb0ef41Sopenharmony_ci } 4371cb0ef41Sopenharmony_ci ] 4381cb0ef41Sopenharmony_ci } 4391cb0ef41Sopenharmony_ci ], 4401cb0ef41Sopenharmony_ci "desc": "<p><strong>Strict assertion mode</strong></p>\n<p>An alias of <a href=\"#assertdeepstrictequalactual-expected-message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<p><strong>Legacy assertion mode</strong></p>\n<blockquote>\n<p>Stability: 3 - Legacy: Use <a href=\"#assertdeepstrictequalactual-expected-message\"><code>assert.deepStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests for deep equality between the <code>actual</code> and <code>expected</code> parameters. Consider\nusing <a href=\"#assertdeepstrictequalactual-expected-message\"><code>assert.deepStrictEqual()</code></a> instead. <a href=\"#assertdeepequalactual-expected-message\"><code>assert.deepEqual()</code></a> can have\nsurprising results.</p>\n<p><em>Deep equality</em> means that the enumerable \"own\" properties of child objects\nare also recursively evaluated by the following rules.</p>", 4411cb0ef41Sopenharmony_ci "modules": [ 4421cb0ef41Sopenharmony_ci { 4431cb0ef41Sopenharmony_ci "textRaw": "Comparison details", 4441cb0ef41Sopenharmony_ci "name": "comparison_details", 4451cb0ef41Sopenharmony_ci "desc": "<ul>\n<li>Primitive values are compared with the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\"><code>==</code> operator</a>,\nwith the exception of <code>NaN</code>. It is treated as being identical in case\nboth sides are <code>NaN</code>.</li>\n<li><a href=\"https://tc39.github.io/ecma262/#sec-object.prototype.tostring\">Type tags</a> of objects should be the same.</li>\n<li>Only <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable \"own\" properties</a> are considered.</li>\n<li><a href=\"errors.html#class-error\"><code>Error</code></a> names and messages are always compared, even if these are not\nenumerable properties.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript\">Object wrappers</a> are compared both as objects and unwrapped values.</li>\n<li><code>Object</code> properties are compared unordered.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> keys and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code>Set</code></a> items are compared unordered.</li>\n<li>Recursion stops when both sides differ or both sides encounter a circular\nreference.</li>\n<li>Implementation does not test the <a href=\"https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots\"><code>[[Prototype]]</code></a> of\nobjects.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\"><code>Symbol</code></a> properties are not compared.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> comparison does not rely on their values.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a> lastIndex, flags, and source are always compared, even if these\nare not enumerable properties.</li>\n</ul>\n<p>The following example does not throw an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> because the\nprimitives are compared using the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\"><code>==</code> operator</a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n// WARNING: This does not throw an AssertionError!\n\nassert.deepEqual('+00000000', false);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n// WARNING: This does not throw an AssertionError!\n\nassert.deepEqual('+00000000', false);\n</code></pre>\n<p>\"Deep\" equality means that the enumerable \"own\" properties of child objects\nare evaluated also:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nconst obj1 = {\n a: {\n b: 1,\n },\n};\nconst obj2 = {\n a: {\n b: 2,\n },\n};\nconst obj3 = {\n a: {\n b: 1,\n },\n};\nconst obj4 = Object.create(obj1);\n\nassert.deepEqual(obj1, obj1);\n// OK\n\n// Values of b are different:\nassert.deepEqual(obj1, obj2);\n// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }\n\nassert.deepEqual(obj1, obj3);\n// OK\n\n// Prototypes are ignored:\nassert.deepEqual(obj1, obj4);\n// AssertionError: { a: { b: 1 } } deepEqual {}\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nconst obj1 = {\n a: {\n b: 1,\n },\n};\nconst obj2 = {\n a: {\n b: 2,\n },\n};\nconst obj3 = {\n a: {\n b: 1,\n },\n};\nconst obj4 = Object.create(obj1);\n\nassert.deepEqual(obj1, obj1);\n// OK\n\n// Values of b are different:\nassert.deepEqual(obj1, obj2);\n// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }\n\nassert.deepEqual(obj1, obj3);\n// OK\n\n// Prototypes are ignored:\nassert.deepEqual(obj1, obj4);\n// AssertionError: { a: { b: 1 } } deepEqual {}\n</code></pre>\n<p>If the values are not equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>", 4461cb0ef41Sopenharmony_ci "type": "module", 4471cb0ef41Sopenharmony_ci "displayName": "Comparison details" 4481cb0ef41Sopenharmony_ci } 4491cb0ef41Sopenharmony_ci ] 4501cb0ef41Sopenharmony_ci }, 4511cb0ef41Sopenharmony_ci { 4521cb0ef41Sopenharmony_ci "textRaw": "`assert.deepStrictEqual(actual, expected[, message])`", 4531cb0ef41Sopenharmony_ci "type": "method", 4541cb0ef41Sopenharmony_ci "name": "deepStrictEqual", 4551cb0ef41Sopenharmony_ci "meta": { 4561cb0ef41Sopenharmony_ci "added": [ 4571cb0ef41Sopenharmony_ci "v1.2.0" 4581cb0ef41Sopenharmony_ci ], 4591cb0ef41Sopenharmony_ci "changes": [ 4601cb0ef41Sopenharmony_ci { 4611cb0ef41Sopenharmony_ci "version": "v18.0.0", 4621cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/41020", 4631cb0ef41Sopenharmony_ci "description": "Regular expressions lastIndex property is now compared as well." 4641cb0ef41Sopenharmony_ci }, 4651cb0ef41Sopenharmony_ci { 4661cb0ef41Sopenharmony_ci "version": "v9.0.0", 4671cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15169", 4681cb0ef41Sopenharmony_ci "description": "Enumerable symbol properties are now compared." 4691cb0ef41Sopenharmony_ci }, 4701cb0ef41Sopenharmony_ci { 4711cb0ef41Sopenharmony_ci "version": "v9.0.0", 4721cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15036", 4731cb0ef41Sopenharmony_ci "description": "The `NaN` is now compared using the [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) comparison." 4741cb0ef41Sopenharmony_ci }, 4751cb0ef41Sopenharmony_ci { 4761cb0ef41Sopenharmony_ci "version": "v8.5.0", 4771cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15001", 4781cb0ef41Sopenharmony_ci "description": "The `Error` names and messages are now properly compared." 4791cb0ef41Sopenharmony_ci }, 4801cb0ef41Sopenharmony_ci { 4811cb0ef41Sopenharmony_ci "version": "v8.0.0", 4821cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/12142", 4831cb0ef41Sopenharmony_ci "description": "The `Set` and `Map` content is also compared." 4841cb0ef41Sopenharmony_ci }, 4851cb0ef41Sopenharmony_ci { 4861cb0ef41Sopenharmony_ci "version": [ 4871cb0ef41Sopenharmony_ci "v6.4.0", 4881cb0ef41Sopenharmony_ci "v4.7.1" 4891cb0ef41Sopenharmony_ci ], 4901cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/8002", 4911cb0ef41Sopenharmony_ci "description": "Typed array slices are handled correctly now." 4921cb0ef41Sopenharmony_ci }, 4931cb0ef41Sopenharmony_ci { 4941cb0ef41Sopenharmony_ci "version": "v6.1.0", 4951cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6432", 4961cb0ef41Sopenharmony_ci "description": "Objects with circular references can be used as inputs now." 4971cb0ef41Sopenharmony_ci }, 4981cb0ef41Sopenharmony_ci { 4991cb0ef41Sopenharmony_ci "version": [ 5001cb0ef41Sopenharmony_ci "v5.10.1", 5011cb0ef41Sopenharmony_ci "v4.4.3" 5021cb0ef41Sopenharmony_ci ], 5031cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/5910", 5041cb0ef41Sopenharmony_ci "description": "Handle non-`Uint8Array` typed arrays correctly." 5051cb0ef41Sopenharmony_ci } 5061cb0ef41Sopenharmony_ci ] 5071cb0ef41Sopenharmony_ci }, 5081cb0ef41Sopenharmony_ci "signatures": [ 5091cb0ef41Sopenharmony_ci { 5101cb0ef41Sopenharmony_ci "params": [ 5111cb0ef41Sopenharmony_ci { 5121cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 5131cb0ef41Sopenharmony_ci "name": "actual", 5141cb0ef41Sopenharmony_ci "type": "any" 5151cb0ef41Sopenharmony_ci }, 5161cb0ef41Sopenharmony_ci { 5171cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 5181cb0ef41Sopenharmony_ci "name": "expected", 5191cb0ef41Sopenharmony_ci "type": "any" 5201cb0ef41Sopenharmony_ci }, 5211cb0ef41Sopenharmony_ci { 5221cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 5231cb0ef41Sopenharmony_ci "name": "message", 5241cb0ef41Sopenharmony_ci "type": "string|Error" 5251cb0ef41Sopenharmony_ci } 5261cb0ef41Sopenharmony_ci ] 5271cb0ef41Sopenharmony_ci } 5281cb0ef41Sopenharmony_ci ], 5291cb0ef41Sopenharmony_ci "desc": "<p>Tests for deep equality between the <code>actual</code> and <code>expected</code> parameters.\n\"Deep\" equality means that the enumerable \"own\" properties of child objects\nare recursively evaluated also by the following rules.</p>", 5301cb0ef41Sopenharmony_ci "modules": [ 5311cb0ef41Sopenharmony_ci { 5321cb0ef41Sopenharmony_ci "textRaw": "Comparison details", 5331cb0ef41Sopenharmony_ci "name": "comparison_details", 5341cb0ef41Sopenharmony_ci "desc": "<ul>\n<li>Primitive values are compared using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\"><code>Object.is()</code></a>.</li>\n<li><a href=\"https://tc39.github.io/ecma262/#sec-object.prototype.tostring\">Type tags</a> of objects should be the same.</li>\n<li><a href=\"https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots\"><code>[[Prototype]]</code></a> of objects are compared using\nthe <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Strict_equality\"><code>===</code> operator</a>.</li>\n<li>Only <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties\">enumerable \"own\" properties</a> are considered.</li>\n<li><a href=\"errors.html#class-error\"><code>Error</code></a> names and messages are always compared, even if these are not\nenumerable properties.</li>\n<li>Enumerable own <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol\"><code>Symbol</code></a> properties are compared as well.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript\">Object wrappers</a> are compared both as objects and unwrapped values.</li>\n<li><code>Object</code> properties are compared unordered.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map\"><code>Map</code></a> keys and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set\"><code>Set</code></a> items are compared unordered.</li>\n<li>Recursion stops when both sides differ or both sides encounter a circular\nreference.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap\"><code>WeakMap</code></a> and <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet\"><code>WeakSet</code></a> comparison does not rely on their values. See\nbelow for further details.</li>\n<li><a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a> lastIndex, flags, and source are always compared, even if these\nare not enumerable properties.</li>\n</ul>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\n// This fails because 1 !== '1'.\nassert.deepStrictEqual({ a: 1 }, { a: '1' });\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// {\n// + a: 1\n// - a: '1'\n// }\n\n// The following objects don't have own properties\nconst date = new Date();\nconst object = {};\nconst fakeDate = {};\nObject.setPrototypeOf(fakeDate, Date.prototype);\n\n// Different [[Prototype]]:\nassert.deepStrictEqual(object, fakeDate);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + {}\n// - Date {}\n\n// Different type tags:\nassert.deepStrictEqual(date, fakeDate);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + 2018-04-26T00:49:08.604Z\n// - Date {}\n\nassert.deepStrictEqual(NaN, NaN);\n// OK because Object.is(NaN, NaN) is true.\n\n// Different unwrapped numbers:\nassert.deepStrictEqual(new Number(1), new Number(2));\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + [Number: 1]\n// - [Number: 2]\n\nassert.deepStrictEqual(new String('foo'), Object('foo'));\n// OK because the object and the string are identical when unwrapped.\n\nassert.deepStrictEqual(-0, -0);\n// OK\n\n// Different zeros:\nassert.deepStrictEqual(0, -0);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + 0\n// - -0\n\nconst symbol1 = Symbol();\nconst symbol2 = Symbol();\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 });\n// OK, because it is the same symbol on both objects.\n\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 });\n// AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:\n//\n// {\n// [Symbol()]: 1\n// }\n\nconst weakMap1 = new WeakMap();\nconst weakMap2 = new WeakMap([[{}, {}]]);\nconst weakMap3 = new WeakMap();\nweakMap3.unequal = true;\n\nassert.deepStrictEqual(weakMap1, weakMap2);\n// OK, because it is impossible to compare the entries\n\n// Fails because weakMap3 has a property that weakMap1 does not contain:\nassert.deepStrictEqual(weakMap1, weakMap3);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// WeakMap {\n// + [items unknown]\n// - [items unknown],\n// - unequal: true\n// }\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\n// This fails because 1 !== '1'.\nassert.deepStrictEqual({ a: 1 }, { a: '1' });\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// {\n// + a: 1\n// - a: '1'\n// }\n\n// The following objects don't have own properties\nconst date = new Date();\nconst object = {};\nconst fakeDate = {};\nObject.setPrototypeOf(fakeDate, Date.prototype);\n\n// Different [[Prototype]]:\nassert.deepStrictEqual(object, fakeDate);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + {}\n// - Date {}\n\n// Different type tags:\nassert.deepStrictEqual(date, fakeDate);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + 2018-04-26T00:49:08.604Z\n// - Date {}\n\nassert.deepStrictEqual(NaN, NaN);\n// OK because Object.is(NaN, NaN) is true.\n\n// Different unwrapped numbers:\nassert.deepStrictEqual(new Number(1), new Number(2));\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + [Number: 1]\n// - [Number: 2]\n\nassert.deepStrictEqual(new String('foo'), Object('foo'));\n// OK because the object and the string are identical when unwrapped.\n\nassert.deepStrictEqual(-0, -0);\n// OK\n\n// Different zeros:\nassert.deepStrictEqual(0, -0);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// + 0\n// - -0\n\nconst symbol1 = Symbol();\nconst symbol2 = Symbol();\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 });\n// OK, because it is the same symbol on both objects.\n\nassert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 });\n// AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal:\n//\n// {\n// [Symbol()]: 1\n// }\n\nconst weakMap1 = new WeakMap();\nconst weakMap2 = new WeakMap([[{}, {}]]);\nconst weakMap3 = new WeakMap();\nweakMap3.unequal = true;\n\nassert.deepStrictEqual(weakMap1, weakMap2);\n// OK, because it is impossible to compare the entries\n\n// Fails because weakMap3 has a property that weakMap1 does not contain:\nassert.deepStrictEqual(weakMap1, weakMap3);\n// AssertionError: Expected inputs to be strictly deep-equal:\n// + actual - expected\n//\n// WeakMap {\n// + [items unknown]\n// - [items unknown],\n// - unequal: true\n// }\n</code></pre>\n<p>If the values are not equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>", 5351cb0ef41Sopenharmony_ci "type": "module", 5361cb0ef41Sopenharmony_ci "displayName": "Comparison details" 5371cb0ef41Sopenharmony_ci } 5381cb0ef41Sopenharmony_ci ] 5391cb0ef41Sopenharmony_ci }, 5401cb0ef41Sopenharmony_ci { 5411cb0ef41Sopenharmony_ci "textRaw": "`assert.doesNotMatch(string, regexp[, message])`", 5421cb0ef41Sopenharmony_ci "type": "method", 5431cb0ef41Sopenharmony_ci "name": "doesNotMatch", 5441cb0ef41Sopenharmony_ci "meta": { 5451cb0ef41Sopenharmony_ci "added": [ 5461cb0ef41Sopenharmony_ci "v13.6.0", 5471cb0ef41Sopenharmony_ci "v12.16.0" 5481cb0ef41Sopenharmony_ci ], 5491cb0ef41Sopenharmony_ci "changes": [ 5501cb0ef41Sopenharmony_ci { 5511cb0ef41Sopenharmony_ci "version": "v16.0.0", 5521cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38111", 5531cb0ef41Sopenharmony_ci "description": "This API is no longer experimental." 5541cb0ef41Sopenharmony_ci } 5551cb0ef41Sopenharmony_ci ] 5561cb0ef41Sopenharmony_ci }, 5571cb0ef41Sopenharmony_ci "signatures": [ 5581cb0ef41Sopenharmony_ci { 5591cb0ef41Sopenharmony_ci "params": [ 5601cb0ef41Sopenharmony_ci { 5611cb0ef41Sopenharmony_ci "textRaw": "`string` {string}", 5621cb0ef41Sopenharmony_ci "name": "string", 5631cb0ef41Sopenharmony_ci "type": "string" 5641cb0ef41Sopenharmony_ci }, 5651cb0ef41Sopenharmony_ci { 5661cb0ef41Sopenharmony_ci "textRaw": "`regexp` {RegExp}", 5671cb0ef41Sopenharmony_ci "name": "regexp", 5681cb0ef41Sopenharmony_ci "type": "RegExp" 5691cb0ef41Sopenharmony_ci }, 5701cb0ef41Sopenharmony_ci { 5711cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 5721cb0ef41Sopenharmony_ci "name": "message", 5731cb0ef41Sopenharmony_ci "type": "string|Error" 5741cb0ef41Sopenharmony_ci } 5751cb0ef41Sopenharmony_ci ] 5761cb0ef41Sopenharmony_ci } 5771cb0ef41Sopenharmony_ci ], 5781cb0ef41Sopenharmony_ci "desc": "<p>Expects the <code>string</code> input not to match the regular expression.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.doesNotMatch('I will fail', /fail/);\n// AssertionError [ERR_ASSERTION]: The input was expected to not match the ...\n\nassert.doesNotMatch(123, /pass/);\n// AssertionError [ERR_ASSERTION]: The \"string\" argument must be of type string.\n\nassert.doesNotMatch('I will pass', /different/);\n// OK\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.doesNotMatch('I will fail', /fail/);\n// AssertionError [ERR_ASSERTION]: The input was expected to not match the ...\n\nassert.doesNotMatch(123, /pass/);\n// AssertionError [ERR_ASSERTION]: The \"string\" argument must be of type string.\n\nassert.doesNotMatch('I will pass', /different/);\n// OK\n</code></pre>\n<p>If the values do match, or if the <code>string</code> argument is of another type than\n<code>string</code>, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code> property set equal\nto the value of the <code>message</code> parameter. If the <code>message</code> parameter is\nundefined, a default error message is assigned. If the <code>message</code> parameter is an\ninstance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>" 5791cb0ef41Sopenharmony_ci }, 5801cb0ef41Sopenharmony_ci { 5811cb0ef41Sopenharmony_ci "textRaw": "`assert.doesNotReject(asyncFn[, error][, message])`", 5821cb0ef41Sopenharmony_ci "type": "method", 5831cb0ef41Sopenharmony_ci "name": "doesNotReject", 5841cb0ef41Sopenharmony_ci "meta": { 5851cb0ef41Sopenharmony_ci "added": [ 5861cb0ef41Sopenharmony_ci "v10.0.0" 5871cb0ef41Sopenharmony_ci ], 5881cb0ef41Sopenharmony_ci "changes": [] 5891cb0ef41Sopenharmony_ci }, 5901cb0ef41Sopenharmony_ci "signatures": [ 5911cb0ef41Sopenharmony_ci { 5921cb0ef41Sopenharmony_ci "params": [ 5931cb0ef41Sopenharmony_ci { 5941cb0ef41Sopenharmony_ci "textRaw": "`asyncFn` {Function|Promise}", 5951cb0ef41Sopenharmony_ci "name": "asyncFn", 5961cb0ef41Sopenharmony_ci "type": "Function|Promise" 5971cb0ef41Sopenharmony_ci }, 5981cb0ef41Sopenharmony_ci { 5991cb0ef41Sopenharmony_ci "textRaw": "`error` {RegExp|Function}", 6001cb0ef41Sopenharmony_ci "name": "error", 6011cb0ef41Sopenharmony_ci "type": "RegExp|Function" 6021cb0ef41Sopenharmony_ci }, 6031cb0ef41Sopenharmony_ci { 6041cb0ef41Sopenharmony_ci "textRaw": "`message` {string}", 6051cb0ef41Sopenharmony_ci "name": "message", 6061cb0ef41Sopenharmony_ci "type": "string" 6071cb0ef41Sopenharmony_ci } 6081cb0ef41Sopenharmony_ci ] 6091cb0ef41Sopenharmony_ci } 6101cb0ef41Sopenharmony_ci ], 6111cb0ef41Sopenharmony_ci "desc": "<p>Awaits the <code>asyncFn</code> promise or, if <code>asyncFn</code> is a function, immediately\ncalls the function and awaits the returned promise to complete. It will then\ncheck that the promise is not rejected.</p>\n<p>If <code>asyncFn</code> is a function and it throws an error synchronously,\n<code>assert.doesNotReject()</code> will return a rejected <code>Promise</code> with that error. If\nthe function does not return a promise, <code>assert.doesNotReject()</code> will return a\nrejected <code>Promise</code> with an <a href=\"errors.html#err_invalid_return_value\"><code>ERR_INVALID_RETURN_VALUE</code></a> error. In both cases\nthe error handler is skipped.</p>\n<p>Using <code>assert.doesNotReject()</code> is actually not useful because there is little\nbenefit in catching a rejection and then rejecting it again. Instead, consider\nadding a comment next to the specific code path that should not reject and keep\nerror messages as expressive as possible.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, or a validation\nfunction. See <a href=\"#assertthrowsfn-error-message\"><code>assert.throws()</code></a> for more details.</p>\n<p>Besides the async nature to await the completion behaves identically to\n<a href=\"#assertdoesnotthrowfn-error-message\"><code>assert.doesNotThrow()</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nawait assert.doesNotReject(\n async () => {\n throw new TypeError('Wrong value');\n },\n SyntaxError,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\n(async () => {\n await assert.doesNotReject(\n async () => {\n throw new TypeError('Wrong value');\n },\n SyntaxError,\n );\n})();\n</code></pre>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.doesNotReject(Promise.reject(new TypeError('Wrong value')))\n .then(() => {\n // ...\n });\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.doesNotReject(Promise.reject(new TypeError('Wrong value')))\n .then(() => {\n // ...\n });\n</code></pre>" 6121cb0ef41Sopenharmony_ci }, 6131cb0ef41Sopenharmony_ci { 6141cb0ef41Sopenharmony_ci "textRaw": "`assert.doesNotThrow(fn[, error][, message])`", 6151cb0ef41Sopenharmony_ci "type": "method", 6161cb0ef41Sopenharmony_ci "name": "doesNotThrow", 6171cb0ef41Sopenharmony_ci "meta": { 6181cb0ef41Sopenharmony_ci "added": [ 6191cb0ef41Sopenharmony_ci "v0.1.21" 6201cb0ef41Sopenharmony_ci ], 6211cb0ef41Sopenharmony_ci "changes": [ 6221cb0ef41Sopenharmony_ci { 6231cb0ef41Sopenharmony_ci "version": [ 6241cb0ef41Sopenharmony_ci "v5.11.0", 6251cb0ef41Sopenharmony_ci "v4.4.5" 6261cb0ef41Sopenharmony_ci ], 6271cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/2407", 6281cb0ef41Sopenharmony_ci "description": "The `message` parameter is respected now." 6291cb0ef41Sopenharmony_ci }, 6301cb0ef41Sopenharmony_ci { 6311cb0ef41Sopenharmony_ci "version": "v4.2.0", 6321cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/3276", 6331cb0ef41Sopenharmony_ci "description": "The `error` parameter can now be an arrow function." 6341cb0ef41Sopenharmony_ci } 6351cb0ef41Sopenharmony_ci ] 6361cb0ef41Sopenharmony_ci }, 6371cb0ef41Sopenharmony_ci "signatures": [ 6381cb0ef41Sopenharmony_ci { 6391cb0ef41Sopenharmony_ci "params": [ 6401cb0ef41Sopenharmony_ci { 6411cb0ef41Sopenharmony_ci "textRaw": "`fn` {Function}", 6421cb0ef41Sopenharmony_ci "name": "fn", 6431cb0ef41Sopenharmony_ci "type": "Function" 6441cb0ef41Sopenharmony_ci }, 6451cb0ef41Sopenharmony_ci { 6461cb0ef41Sopenharmony_ci "textRaw": "`error` {RegExp|Function}", 6471cb0ef41Sopenharmony_ci "name": "error", 6481cb0ef41Sopenharmony_ci "type": "RegExp|Function" 6491cb0ef41Sopenharmony_ci }, 6501cb0ef41Sopenharmony_ci { 6511cb0ef41Sopenharmony_ci "textRaw": "`message` {string}", 6521cb0ef41Sopenharmony_ci "name": "message", 6531cb0ef41Sopenharmony_ci "type": "string" 6541cb0ef41Sopenharmony_ci } 6551cb0ef41Sopenharmony_ci ] 6561cb0ef41Sopenharmony_ci } 6571cb0ef41Sopenharmony_ci ], 6581cb0ef41Sopenharmony_ci "desc": "<p>Asserts that the function <code>fn</code> does not throw an error.</p>\n<p>Using <code>assert.doesNotThrow()</code> is actually not useful because there\nis no benefit in catching an error and then rethrowing it. Instead, consider\nadding a comment next to the specific code path that should not throw and keep\nerror messages as expressive as possible.</p>\n<p>When <code>assert.doesNotThrow()</code> is called, it will immediately call the <code>fn</code>\nfunction.</p>\n<p>If an error is thrown and it is the same type as that specified by the <code>error</code>\nparameter, then an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown. If the error is of a\ndifferent type, or if the <code>error</code> parameter is undefined, the error is\npropagated back to the caller.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, or a validation\nfunction. See <a href=\"#assertthrowsfn-error-message\"><code>assert.throws()</code></a> for more details.</p>\n<p>The following, for instance, will throw the <a href=\"errors.html#class-typeerror\"><code>TypeError</code></a> because there is no\nmatching error type in the assertion:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n SyntaxError,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n SyntaxError,\n);\n</code></pre>\n<p>However, the following will result in an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> with the message\n'Got unwanted exception...':</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n TypeError,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n TypeError,\n);\n</code></pre>\n<p>If an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown and a value is provided for the <code>message</code>\nparameter, the value of <code>message</code> will be appended to the <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>\nmessage:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n /Wrong value/,\n 'Whoops',\n);\n// Throws: AssertionError: Got unwanted exception: Whoops\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.doesNotThrow(\n () => {\n throw new TypeError('Wrong value');\n },\n /Wrong value/,\n 'Whoops',\n);\n// Throws: AssertionError: Got unwanted exception: Whoops\n</code></pre>" 6591cb0ef41Sopenharmony_ci }, 6601cb0ef41Sopenharmony_ci { 6611cb0ef41Sopenharmony_ci "textRaw": "`assert.equal(actual, expected[, message])`", 6621cb0ef41Sopenharmony_ci "type": "method", 6631cb0ef41Sopenharmony_ci "name": "equal", 6641cb0ef41Sopenharmony_ci "meta": { 6651cb0ef41Sopenharmony_ci "added": [ 6661cb0ef41Sopenharmony_ci "v0.1.21" 6671cb0ef41Sopenharmony_ci ], 6681cb0ef41Sopenharmony_ci "changes": [ 6691cb0ef41Sopenharmony_ci { 6701cb0ef41Sopenharmony_ci "version": [ 6711cb0ef41Sopenharmony_ci "v16.0.0", 6721cb0ef41Sopenharmony_ci "v14.18.0" 6731cb0ef41Sopenharmony_ci ], 6741cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38113", 6751cb0ef41Sopenharmony_ci "description": "In Legacy assertion mode, changed status from Deprecated to Legacy." 6761cb0ef41Sopenharmony_ci }, 6771cb0ef41Sopenharmony_ci { 6781cb0ef41Sopenharmony_ci "version": "v14.0.0", 6791cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/30766", 6801cb0ef41Sopenharmony_ci "description": "NaN is now treated as being identical if both sides are NaN." 6811cb0ef41Sopenharmony_ci } 6821cb0ef41Sopenharmony_ci ] 6831cb0ef41Sopenharmony_ci }, 6841cb0ef41Sopenharmony_ci "signatures": [ 6851cb0ef41Sopenharmony_ci { 6861cb0ef41Sopenharmony_ci "params": [ 6871cb0ef41Sopenharmony_ci { 6881cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 6891cb0ef41Sopenharmony_ci "name": "actual", 6901cb0ef41Sopenharmony_ci "type": "any" 6911cb0ef41Sopenharmony_ci }, 6921cb0ef41Sopenharmony_ci { 6931cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 6941cb0ef41Sopenharmony_ci "name": "expected", 6951cb0ef41Sopenharmony_ci "type": "any" 6961cb0ef41Sopenharmony_ci }, 6971cb0ef41Sopenharmony_ci { 6981cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 6991cb0ef41Sopenharmony_ci "name": "message", 7001cb0ef41Sopenharmony_ci "type": "string|Error" 7011cb0ef41Sopenharmony_ci } 7021cb0ef41Sopenharmony_ci ] 7031cb0ef41Sopenharmony_ci } 7041cb0ef41Sopenharmony_ci ], 7051cb0ef41Sopenharmony_ci "desc": "<p><strong>Strict assertion mode</strong></p>\n<p>An alias of <a href=\"#assertstrictequalactual-expected-message\"><code>assert.strictEqual()</code></a>.</p>\n<p><strong>Legacy assertion mode</strong></p>\n<blockquote>\n<p>Stability: 3 - Legacy: Use <a href=\"#assertstrictequalactual-expected-message\"><code>assert.strictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests shallow, coercive equality between the <code>actual</code> and <code>expected</code> parameters\nusing the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality\"><code>==</code> operator</a>. <code>NaN</code> is specially handled\nand treated as being identical if both sides are <code>NaN</code>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nassert.equal(1, 1);\n// OK, 1 == 1\nassert.equal(1, '1');\n// OK, 1 == '1'\nassert.equal(NaN, NaN);\n// OK\n\nassert.equal(1, 2);\n// AssertionError: 1 == 2\nassert.equal({ a: { b: 1 } }, { a: { b: 1 } });\n// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nassert.equal(1, 1);\n// OK, 1 == 1\nassert.equal(1, '1');\n// OK, 1 == '1'\nassert.equal(NaN, NaN);\n// OK\n\nassert.equal(1, 2);\n// AssertionError: 1 == 2\nassert.equal({ a: { b: 1 } }, { a: { b: 1 } });\n// AssertionError: { a: { b: 1 } } == { a: { b: 1 } }\n</code></pre>\n<p>If the values are not equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>" 7061cb0ef41Sopenharmony_ci }, 7071cb0ef41Sopenharmony_ci { 7081cb0ef41Sopenharmony_ci "textRaw": "`assert.fail([message])`", 7091cb0ef41Sopenharmony_ci "type": "method", 7101cb0ef41Sopenharmony_ci "name": "fail", 7111cb0ef41Sopenharmony_ci "meta": { 7121cb0ef41Sopenharmony_ci "added": [ 7131cb0ef41Sopenharmony_ci "v0.1.21" 7141cb0ef41Sopenharmony_ci ], 7151cb0ef41Sopenharmony_ci "changes": [] 7161cb0ef41Sopenharmony_ci }, 7171cb0ef41Sopenharmony_ci "signatures": [ 7181cb0ef41Sopenharmony_ci { 7191cb0ef41Sopenharmony_ci "params": [ 7201cb0ef41Sopenharmony_ci { 7211cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error} **Default:** `'Failed'`", 7221cb0ef41Sopenharmony_ci "name": "message", 7231cb0ef41Sopenharmony_ci "type": "string|Error", 7241cb0ef41Sopenharmony_ci "default": "`'Failed'`" 7251cb0ef41Sopenharmony_ci } 7261cb0ef41Sopenharmony_ci ] 7271cb0ef41Sopenharmony_ci } 7281cb0ef41Sopenharmony_ci ], 7291cb0ef41Sopenharmony_ci "desc": "<p>Throws an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> with the provided error message or a default\nerror message. If the <code>message</code> parameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then\nit will be thrown instead of the <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.fail();\n// AssertionError [ERR_ASSERTION]: Failed\n\nassert.fail('boom');\n// AssertionError [ERR_ASSERTION]: boom\n\nassert.fail(new TypeError('need array'));\n// TypeError: need array\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.fail();\n// AssertionError [ERR_ASSERTION]: Failed\n\nassert.fail('boom');\n// AssertionError [ERR_ASSERTION]: boom\n\nassert.fail(new TypeError('need array'));\n// TypeError: need array\n</code></pre>\n<p>Using <code>assert.fail()</code> with more than two arguments is possible but deprecated.\nSee below for further details.</p>" 7301cb0ef41Sopenharmony_ci }, 7311cb0ef41Sopenharmony_ci { 7321cb0ef41Sopenharmony_ci "textRaw": "`assert.fail(actual, expected[, message[, operator[, stackStartFn]]])`", 7331cb0ef41Sopenharmony_ci "type": "method", 7341cb0ef41Sopenharmony_ci "name": "fail", 7351cb0ef41Sopenharmony_ci "meta": { 7361cb0ef41Sopenharmony_ci "added": [ 7371cb0ef41Sopenharmony_ci "v0.1.21" 7381cb0ef41Sopenharmony_ci ], 7391cb0ef41Sopenharmony_ci "changes": [ 7401cb0ef41Sopenharmony_ci { 7411cb0ef41Sopenharmony_ci "version": "v10.0.0", 7421cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/18418", 7431cb0ef41Sopenharmony_ci "description": "Calling `assert.fail()` with more than one argument is deprecated and emits a warning." 7441cb0ef41Sopenharmony_ci } 7451cb0ef41Sopenharmony_ci ] 7461cb0ef41Sopenharmony_ci }, 7471cb0ef41Sopenharmony_ci "stability": 0, 7481cb0ef41Sopenharmony_ci "stabilityText": "Deprecated: Use `assert.fail([message])` or other assert functions instead.", 7491cb0ef41Sopenharmony_ci "signatures": [ 7501cb0ef41Sopenharmony_ci { 7511cb0ef41Sopenharmony_ci "params": [ 7521cb0ef41Sopenharmony_ci { 7531cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 7541cb0ef41Sopenharmony_ci "name": "actual", 7551cb0ef41Sopenharmony_ci "type": "any" 7561cb0ef41Sopenharmony_ci }, 7571cb0ef41Sopenharmony_ci { 7581cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 7591cb0ef41Sopenharmony_ci "name": "expected", 7601cb0ef41Sopenharmony_ci "type": "any" 7611cb0ef41Sopenharmony_ci }, 7621cb0ef41Sopenharmony_ci { 7631cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 7641cb0ef41Sopenharmony_ci "name": "message", 7651cb0ef41Sopenharmony_ci "type": "string|Error" 7661cb0ef41Sopenharmony_ci }, 7671cb0ef41Sopenharmony_ci { 7681cb0ef41Sopenharmony_ci "textRaw": "`operator` {string} **Default:** `'!='`", 7691cb0ef41Sopenharmony_ci "name": "operator", 7701cb0ef41Sopenharmony_ci "type": "string", 7711cb0ef41Sopenharmony_ci "default": "`'!='`" 7721cb0ef41Sopenharmony_ci }, 7731cb0ef41Sopenharmony_ci { 7741cb0ef41Sopenharmony_ci "textRaw": "`stackStartFn` {Function} **Default:** `assert.fail`", 7751cb0ef41Sopenharmony_ci "name": "stackStartFn", 7761cb0ef41Sopenharmony_ci "type": "Function", 7771cb0ef41Sopenharmony_ci "default": "`assert.fail`" 7781cb0ef41Sopenharmony_ci } 7791cb0ef41Sopenharmony_ci ] 7801cb0ef41Sopenharmony_ci } 7811cb0ef41Sopenharmony_ci ], 7821cb0ef41Sopenharmony_ci "desc": "<p>If <code>message</code> is falsy, the error message is set as the values of <code>actual</code> and\n<code>expected</code> separated by the provided <code>operator</code>. If just the two <code>actual</code> and\n<code>expected</code> arguments are provided, <code>operator</code> will default to <code>'!='</code>. If\n<code>message</code> is provided as third argument it will be used as the error message and\nthe other arguments will be stored as properties on the thrown object. If\n<code>stackStartFn</code> is provided, all stack frames above that function will be\nremoved from stacktrace (see <a href=\"errors.html#errorcapturestacktracetargetobject-constructoropt\"><code>Error.captureStackTrace</code></a>). If no arguments are\ngiven, the default message <code>Failed</code> will be used.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.fail('a', 'b');\n// AssertionError [ERR_ASSERTION]: 'a' != 'b'\n\nassert.fail(1, 2, undefined, '>');\n// AssertionError [ERR_ASSERTION]: 1 > 2\n\nassert.fail(1, 2, 'fail');\n// AssertionError [ERR_ASSERTION]: fail\n\nassert.fail(1, 2, 'whoops', '>');\n// AssertionError [ERR_ASSERTION]: whoops\n\nassert.fail(1, 2, new TypeError('need array'));\n// TypeError: need array\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.fail('a', 'b');\n// AssertionError [ERR_ASSERTION]: 'a' != 'b'\n\nassert.fail(1, 2, undefined, '>');\n// AssertionError [ERR_ASSERTION]: 1 > 2\n\nassert.fail(1, 2, 'fail');\n// AssertionError [ERR_ASSERTION]: fail\n\nassert.fail(1, 2, 'whoops', '>');\n// AssertionError [ERR_ASSERTION]: whoops\n\nassert.fail(1, 2, new TypeError('need array'));\n// TypeError: need array\n</code></pre>\n<p>In the last three cases <code>actual</code>, <code>expected</code>, and <code>operator</code> have no\ninfluence on the error message.</p>\n<p>Example use of <code>stackStartFn</code> for truncating the exception's stacktrace:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nfunction suppressFrame() {\n assert.fail('a', 'b', undefined, '!==', suppressFrame);\n}\nsuppressFrame();\n// AssertionError [ERR_ASSERTION]: 'a' !== 'b'\n// at repl:1:1\n// at ContextifyScript.Script.runInThisContext (vm.js:44:33)\n// ...\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nfunction suppressFrame() {\n assert.fail('a', 'b', undefined, '!==', suppressFrame);\n}\nsuppressFrame();\n// AssertionError [ERR_ASSERTION]: 'a' !== 'b'\n// at repl:1:1\n// at ContextifyScript.Script.runInThisContext (vm.js:44:33)\n// ...\n</code></pre>" 7831cb0ef41Sopenharmony_ci }, 7841cb0ef41Sopenharmony_ci { 7851cb0ef41Sopenharmony_ci "textRaw": "`assert.ifError(value)`", 7861cb0ef41Sopenharmony_ci "type": "method", 7871cb0ef41Sopenharmony_ci "name": "ifError", 7881cb0ef41Sopenharmony_ci "meta": { 7891cb0ef41Sopenharmony_ci "added": [ 7901cb0ef41Sopenharmony_ci "v0.1.97" 7911cb0ef41Sopenharmony_ci ], 7921cb0ef41Sopenharmony_ci "changes": [ 7931cb0ef41Sopenharmony_ci { 7941cb0ef41Sopenharmony_ci "version": "v10.0.0", 7951cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/18247", 7961cb0ef41Sopenharmony_ci "description": "Instead of throwing the original error it is now wrapped into an [`AssertionError`][] that contains the full stack trace." 7971cb0ef41Sopenharmony_ci }, 7981cb0ef41Sopenharmony_ci { 7991cb0ef41Sopenharmony_ci "version": "v10.0.0", 8001cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/18247", 8011cb0ef41Sopenharmony_ci "description": "Value may now only be `undefined` or `null`. Before all falsy values were handled the same as `null` and did not throw." 8021cb0ef41Sopenharmony_ci } 8031cb0ef41Sopenharmony_ci ] 8041cb0ef41Sopenharmony_ci }, 8051cb0ef41Sopenharmony_ci "signatures": [ 8061cb0ef41Sopenharmony_ci { 8071cb0ef41Sopenharmony_ci "params": [ 8081cb0ef41Sopenharmony_ci { 8091cb0ef41Sopenharmony_ci "textRaw": "`value` {any}", 8101cb0ef41Sopenharmony_ci "name": "value", 8111cb0ef41Sopenharmony_ci "type": "any" 8121cb0ef41Sopenharmony_ci } 8131cb0ef41Sopenharmony_ci ] 8141cb0ef41Sopenharmony_ci } 8151cb0ef41Sopenharmony_ci ], 8161cb0ef41Sopenharmony_ci "desc": "<p>Throws <code>value</code> if <code>value</code> is not <code>undefined</code> or <code>null</code>. This is useful when\ntesting the <code>error</code> argument in callbacks. The stack trace contains all frames\nfrom the error passed to <code>ifError()</code> including the potential new frames for\n<code>ifError()</code> itself.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.ifError(null);\n// OK\nassert.ifError(0);\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0\nassert.ifError('error');\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'\nassert.ifError(new Error());\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error\n\n// Create some random error frames.\nlet err;\n(function errorFrame() {\n err = new Error('test error');\n})();\n\n(function ifErrorFrame() {\n assert.ifError(err);\n})();\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error\n// at ifErrorFrame\n// at errorFrame\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.ifError(null);\n// OK\nassert.ifError(0);\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0\nassert.ifError('error');\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error'\nassert.ifError(new Error());\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error\n\n// Create some random error frames.\nlet err;\n(function errorFrame() {\n err = new Error('test error');\n})();\n\n(function ifErrorFrame() {\n assert.ifError(err);\n})();\n// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error\n// at ifErrorFrame\n// at errorFrame\n</code></pre>" 8171cb0ef41Sopenharmony_ci }, 8181cb0ef41Sopenharmony_ci { 8191cb0ef41Sopenharmony_ci "textRaw": "`assert.match(string, regexp[, message])`", 8201cb0ef41Sopenharmony_ci "type": "method", 8211cb0ef41Sopenharmony_ci "name": "match", 8221cb0ef41Sopenharmony_ci "meta": { 8231cb0ef41Sopenharmony_ci "added": [ 8241cb0ef41Sopenharmony_ci "v13.6.0", 8251cb0ef41Sopenharmony_ci "v12.16.0" 8261cb0ef41Sopenharmony_ci ], 8271cb0ef41Sopenharmony_ci "changes": [ 8281cb0ef41Sopenharmony_ci { 8291cb0ef41Sopenharmony_ci "version": "v16.0.0", 8301cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38111", 8311cb0ef41Sopenharmony_ci "description": "This API is no longer experimental." 8321cb0ef41Sopenharmony_ci } 8331cb0ef41Sopenharmony_ci ] 8341cb0ef41Sopenharmony_ci }, 8351cb0ef41Sopenharmony_ci "signatures": [ 8361cb0ef41Sopenharmony_ci { 8371cb0ef41Sopenharmony_ci "params": [ 8381cb0ef41Sopenharmony_ci { 8391cb0ef41Sopenharmony_ci "textRaw": "`string` {string}", 8401cb0ef41Sopenharmony_ci "name": "string", 8411cb0ef41Sopenharmony_ci "type": "string" 8421cb0ef41Sopenharmony_ci }, 8431cb0ef41Sopenharmony_ci { 8441cb0ef41Sopenharmony_ci "textRaw": "`regexp` {RegExp}", 8451cb0ef41Sopenharmony_ci "name": "regexp", 8461cb0ef41Sopenharmony_ci "type": "RegExp" 8471cb0ef41Sopenharmony_ci }, 8481cb0ef41Sopenharmony_ci { 8491cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 8501cb0ef41Sopenharmony_ci "name": "message", 8511cb0ef41Sopenharmony_ci "type": "string|Error" 8521cb0ef41Sopenharmony_ci } 8531cb0ef41Sopenharmony_ci ] 8541cb0ef41Sopenharmony_ci } 8551cb0ef41Sopenharmony_ci ], 8561cb0ef41Sopenharmony_ci "desc": "<p>Expects the <code>string</code> input to match the regular expression.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.match('I will fail', /pass/);\n// AssertionError [ERR_ASSERTION]: The input did not match the regular ...\n\nassert.match(123, /pass/);\n// AssertionError [ERR_ASSERTION]: The \"string\" argument must be of type string.\n\nassert.match('I will pass', /pass/);\n// OK\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.match('I will fail', /pass/);\n// AssertionError [ERR_ASSERTION]: The input did not match the regular ...\n\nassert.match(123, /pass/);\n// AssertionError [ERR_ASSERTION]: The \"string\" argument must be of type string.\n\nassert.match('I will pass', /pass/);\n// OK\n</code></pre>\n<p>If the values do not match, or if the <code>string</code> argument is of another type than\n<code>string</code>, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code> property set equal\nto the value of the <code>message</code> parameter. If the <code>message</code> parameter is\nundefined, a default error message is assigned. If the <code>message</code> parameter is an\ninstance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>" 8571cb0ef41Sopenharmony_ci }, 8581cb0ef41Sopenharmony_ci { 8591cb0ef41Sopenharmony_ci "textRaw": "`assert.notDeepEqual(actual, expected[, message])`", 8601cb0ef41Sopenharmony_ci "type": "method", 8611cb0ef41Sopenharmony_ci "name": "notDeepEqual", 8621cb0ef41Sopenharmony_ci "meta": { 8631cb0ef41Sopenharmony_ci "added": [ 8641cb0ef41Sopenharmony_ci "v0.1.21" 8651cb0ef41Sopenharmony_ci ], 8661cb0ef41Sopenharmony_ci "changes": [ 8671cb0ef41Sopenharmony_ci { 8681cb0ef41Sopenharmony_ci "version": [ 8691cb0ef41Sopenharmony_ci "v16.0.0", 8701cb0ef41Sopenharmony_ci "v14.18.0" 8711cb0ef41Sopenharmony_ci ], 8721cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38113", 8731cb0ef41Sopenharmony_ci "description": "In Legacy assertion mode, changed status from Deprecated to Legacy." 8741cb0ef41Sopenharmony_ci }, 8751cb0ef41Sopenharmony_ci { 8761cb0ef41Sopenharmony_ci "version": "v14.0.0", 8771cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/30766", 8781cb0ef41Sopenharmony_ci "description": "NaN is now treated as being identical if both sides are NaN." 8791cb0ef41Sopenharmony_ci }, 8801cb0ef41Sopenharmony_ci { 8811cb0ef41Sopenharmony_ci "version": "v9.0.0", 8821cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15001", 8831cb0ef41Sopenharmony_ci "description": "The `Error` names and messages are now properly compared." 8841cb0ef41Sopenharmony_ci }, 8851cb0ef41Sopenharmony_ci { 8861cb0ef41Sopenharmony_ci "version": "v8.0.0", 8871cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/12142", 8881cb0ef41Sopenharmony_ci "description": "The `Set` and `Map` content is also compared." 8891cb0ef41Sopenharmony_ci }, 8901cb0ef41Sopenharmony_ci { 8911cb0ef41Sopenharmony_ci "version": [ 8921cb0ef41Sopenharmony_ci "v6.4.0", 8931cb0ef41Sopenharmony_ci "v4.7.1" 8941cb0ef41Sopenharmony_ci ], 8951cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/8002", 8961cb0ef41Sopenharmony_ci "description": "Typed array slices are handled correctly now." 8971cb0ef41Sopenharmony_ci }, 8981cb0ef41Sopenharmony_ci { 8991cb0ef41Sopenharmony_ci "version": [ 9001cb0ef41Sopenharmony_ci "v6.1.0", 9011cb0ef41Sopenharmony_ci "v4.5.0" 9021cb0ef41Sopenharmony_ci ], 9031cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6432", 9041cb0ef41Sopenharmony_ci "description": "Objects with circular references can be used as inputs now." 9051cb0ef41Sopenharmony_ci }, 9061cb0ef41Sopenharmony_ci { 9071cb0ef41Sopenharmony_ci "version": [ 9081cb0ef41Sopenharmony_ci "v5.10.1", 9091cb0ef41Sopenharmony_ci "v4.4.3" 9101cb0ef41Sopenharmony_ci ], 9111cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/5910", 9121cb0ef41Sopenharmony_ci "description": "Handle non-`Uint8Array` typed arrays correctly." 9131cb0ef41Sopenharmony_ci } 9141cb0ef41Sopenharmony_ci ] 9151cb0ef41Sopenharmony_ci }, 9161cb0ef41Sopenharmony_ci "signatures": [ 9171cb0ef41Sopenharmony_ci { 9181cb0ef41Sopenharmony_ci "params": [ 9191cb0ef41Sopenharmony_ci { 9201cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 9211cb0ef41Sopenharmony_ci "name": "actual", 9221cb0ef41Sopenharmony_ci "type": "any" 9231cb0ef41Sopenharmony_ci }, 9241cb0ef41Sopenharmony_ci { 9251cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 9261cb0ef41Sopenharmony_ci "name": "expected", 9271cb0ef41Sopenharmony_ci "type": "any" 9281cb0ef41Sopenharmony_ci }, 9291cb0ef41Sopenharmony_ci { 9301cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 9311cb0ef41Sopenharmony_ci "name": "message", 9321cb0ef41Sopenharmony_ci "type": "string|Error" 9331cb0ef41Sopenharmony_ci } 9341cb0ef41Sopenharmony_ci ] 9351cb0ef41Sopenharmony_ci } 9361cb0ef41Sopenharmony_ci ], 9371cb0ef41Sopenharmony_ci "desc": "<p><strong>Strict assertion mode</strong></p>\n<p>An alias of <a href=\"#assertnotdeepstrictequalactual-expected-message\"><code>assert.notDeepStrictEqual()</code></a>.</p>\n<p><strong>Legacy assertion mode</strong></p>\n<blockquote>\n<p>Stability: 3 - Legacy: Use <a href=\"#assertnotdeepstrictequalactual-expected-message\"><code>assert.notDeepStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests for any deep inequality. Opposite of <a href=\"#assertdeepequalactual-expected-message\"><code>assert.deepEqual()</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nconst obj1 = {\n a: {\n b: 1,\n },\n};\nconst obj2 = {\n a: {\n b: 2,\n },\n};\nconst obj3 = {\n a: {\n b: 1,\n },\n};\nconst obj4 = Object.create(obj1);\n\nassert.notDeepEqual(obj1, obj1);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj2);\n// OK\n\nassert.notDeepEqual(obj1, obj3);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj4);\n// OK\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nconst obj1 = {\n a: {\n b: 1,\n },\n};\nconst obj2 = {\n a: {\n b: 2,\n },\n};\nconst obj3 = {\n a: {\n b: 1,\n },\n};\nconst obj4 = Object.create(obj1);\n\nassert.notDeepEqual(obj1, obj1);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj2);\n// OK\n\nassert.notDeepEqual(obj1, obj3);\n// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }\n\nassert.notDeepEqual(obj1, obj4);\n// OK\n</code></pre>\n<p>If the values are deeply equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned. If the\n<code>message</code> parameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown\ninstead of the <code>AssertionError</code>.</p>" 9381cb0ef41Sopenharmony_ci }, 9391cb0ef41Sopenharmony_ci { 9401cb0ef41Sopenharmony_ci "textRaw": "`assert.notDeepStrictEqual(actual, expected[, message])`", 9411cb0ef41Sopenharmony_ci "type": "method", 9421cb0ef41Sopenharmony_ci "name": "notDeepStrictEqual", 9431cb0ef41Sopenharmony_ci "meta": { 9441cb0ef41Sopenharmony_ci "added": [ 9451cb0ef41Sopenharmony_ci "v1.2.0" 9461cb0ef41Sopenharmony_ci ], 9471cb0ef41Sopenharmony_ci "changes": [ 9481cb0ef41Sopenharmony_ci { 9491cb0ef41Sopenharmony_ci "version": "v9.0.0", 9501cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15398", 9511cb0ef41Sopenharmony_ci "description": "The `-0` and `+0` are not considered equal anymore." 9521cb0ef41Sopenharmony_ci }, 9531cb0ef41Sopenharmony_ci { 9541cb0ef41Sopenharmony_ci "version": "v9.0.0", 9551cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15036", 9561cb0ef41Sopenharmony_ci "description": "The `NaN` is now compared using the [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) comparison." 9571cb0ef41Sopenharmony_ci }, 9581cb0ef41Sopenharmony_ci { 9591cb0ef41Sopenharmony_ci "version": "v9.0.0", 9601cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/15001", 9611cb0ef41Sopenharmony_ci "description": "The `Error` names and messages are now properly compared." 9621cb0ef41Sopenharmony_ci }, 9631cb0ef41Sopenharmony_ci { 9641cb0ef41Sopenharmony_ci "version": "v8.0.0", 9651cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/12142", 9661cb0ef41Sopenharmony_ci "description": "The `Set` and `Map` content is also compared." 9671cb0ef41Sopenharmony_ci }, 9681cb0ef41Sopenharmony_ci { 9691cb0ef41Sopenharmony_ci "version": [ 9701cb0ef41Sopenharmony_ci "v6.4.0", 9711cb0ef41Sopenharmony_ci "v4.7.1" 9721cb0ef41Sopenharmony_ci ], 9731cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/8002", 9741cb0ef41Sopenharmony_ci "description": "Typed array slices are handled correctly now." 9751cb0ef41Sopenharmony_ci }, 9761cb0ef41Sopenharmony_ci { 9771cb0ef41Sopenharmony_ci "version": "v6.1.0", 9781cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/6432", 9791cb0ef41Sopenharmony_ci "description": "Objects with circular references can be used as inputs now." 9801cb0ef41Sopenharmony_ci }, 9811cb0ef41Sopenharmony_ci { 9821cb0ef41Sopenharmony_ci "version": [ 9831cb0ef41Sopenharmony_ci "v5.10.1", 9841cb0ef41Sopenharmony_ci "v4.4.3" 9851cb0ef41Sopenharmony_ci ], 9861cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/5910", 9871cb0ef41Sopenharmony_ci "description": "Handle non-`Uint8Array` typed arrays correctly." 9881cb0ef41Sopenharmony_ci } 9891cb0ef41Sopenharmony_ci ] 9901cb0ef41Sopenharmony_ci }, 9911cb0ef41Sopenharmony_ci "signatures": [ 9921cb0ef41Sopenharmony_ci { 9931cb0ef41Sopenharmony_ci "params": [ 9941cb0ef41Sopenharmony_ci { 9951cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 9961cb0ef41Sopenharmony_ci "name": "actual", 9971cb0ef41Sopenharmony_ci "type": "any" 9981cb0ef41Sopenharmony_ci }, 9991cb0ef41Sopenharmony_ci { 10001cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 10011cb0ef41Sopenharmony_ci "name": "expected", 10021cb0ef41Sopenharmony_ci "type": "any" 10031cb0ef41Sopenharmony_ci }, 10041cb0ef41Sopenharmony_ci { 10051cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 10061cb0ef41Sopenharmony_ci "name": "message", 10071cb0ef41Sopenharmony_ci "type": "string|Error" 10081cb0ef41Sopenharmony_ci } 10091cb0ef41Sopenharmony_ci ] 10101cb0ef41Sopenharmony_ci } 10111cb0ef41Sopenharmony_ci ], 10121cb0ef41Sopenharmony_ci "desc": "<p>Tests for deep strict inequality. Opposite of <a href=\"#assertdeepstrictequalactual-expected-message\"><code>assert.deepStrictEqual()</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.notDeepStrictEqual({ a: 1 }, { a: '1' });\n// OK\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.notDeepStrictEqual({ a: 1 }, { a: '1' });\n// OK\n</code></pre>\n<p>If the values are deeply and strictly equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown\nwith a <code>message</code> property set equal to the value of the <code>message</code> parameter. If\nthe <code>message</code> parameter is undefined, a default error message is assigned. If\nthe <code>message</code> parameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown\ninstead of the <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>" 10131cb0ef41Sopenharmony_ci }, 10141cb0ef41Sopenharmony_ci { 10151cb0ef41Sopenharmony_ci "textRaw": "`assert.notEqual(actual, expected[, message])`", 10161cb0ef41Sopenharmony_ci "type": "method", 10171cb0ef41Sopenharmony_ci "name": "notEqual", 10181cb0ef41Sopenharmony_ci "meta": { 10191cb0ef41Sopenharmony_ci "added": [ 10201cb0ef41Sopenharmony_ci "v0.1.21" 10211cb0ef41Sopenharmony_ci ], 10221cb0ef41Sopenharmony_ci "changes": [ 10231cb0ef41Sopenharmony_ci { 10241cb0ef41Sopenharmony_ci "version": [ 10251cb0ef41Sopenharmony_ci "v16.0.0", 10261cb0ef41Sopenharmony_ci "v14.18.0" 10271cb0ef41Sopenharmony_ci ], 10281cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/38113", 10291cb0ef41Sopenharmony_ci "description": "In Legacy assertion mode, changed status from Deprecated to Legacy." 10301cb0ef41Sopenharmony_ci }, 10311cb0ef41Sopenharmony_ci { 10321cb0ef41Sopenharmony_ci "version": "v14.0.0", 10331cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/30766", 10341cb0ef41Sopenharmony_ci "description": "NaN is now treated as being identical if both sides are NaN." 10351cb0ef41Sopenharmony_ci } 10361cb0ef41Sopenharmony_ci ] 10371cb0ef41Sopenharmony_ci }, 10381cb0ef41Sopenharmony_ci "signatures": [ 10391cb0ef41Sopenharmony_ci { 10401cb0ef41Sopenharmony_ci "params": [ 10411cb0ef41Sopenharmony_ci { 10421cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 10431cb0ef41Sopenharmony_ci "name": "actual", 10441cb0ef41Sopenharmony_ci "type": "any" 10451cb0ef41Sopenharmony_ci }, 10461cb0ef41Sopenharmony_ci { 10471cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 10481cb0ef41Sopenharmony_ci "name": "expected", 10491cb0ef41Sopenharmony_ci "type": "any" 10501cb0ef41Sopenharmony_ci }, 10511cb0ef41Sopenharmony_ci { 10521cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 10531cb0ef41Sopenharmony_ci "name": "message", 10541cb0ef41Sopenharmony_ci "type": "string|Error" 10551cb0ef41Sopenharmony_ci } 10561cb0ef41Sopenharmony_ci ] 10571cb0ef41Sopenharmony_ci } 10581cb0ef41Sopenharmony_ci ], 10591cb0ef41Sopenharmony_ci "desc": "<p><strong>Strict assertion mode</strong></p>\n<p>An alias of <a href=\"#assertnotstrictequalactual-expected-message\"><code>assert.notStrictEqual()</code></a>.</p>\n<p><strong>Legacy assertion mode</strong></p>\n<blockquote>\n<p>Stability: 3 - Legacy: Use <a href=\"#assertnotstrictequalactual-expected-message\"><code>assert.notStrictEqual()</code></a> instead.</p>\n</blockquote>\n<p>Tests shallow, coercive inequality with the <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Inequality\"><code>!=</code> operator</a>. <code>NaN</code> is\nspecially handled and treated as being identical if both sides are <code>NaN</code>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert';\n\nassert.notEqual(1, 2);\n// OK\n\nassert.notEqual(1, 1);\n// AssertionError: 1 != 1\n\nassert.notEqual(1, '1');\n// AssertionError: 1 != '1'\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\nassert.notEqual(1, 2);\n// OK\n\nassert.notEqual(1, 1);\n// AssertionError: 1 != 1\n\nassert.notEqual(1, '1');\n// AssertionError: 1 != '1'\n</code></pre>\n<p>If the values are equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is undefined, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.</p>" 10601cb0ef41Sopenharmony_ci }, 10611cb0ef41Sopenharmony_ci { 10621cb0ef41Sopenharmony_ci "textRaw": "`assert.notStrictEqual(actual, expected[, message])`", 10631cb0ef41Sopenharmony_ci "type": "method", 10641cb0ef41Sopenharmony_ci "name": "notStrictEqual", 10651cb0ef41Sopenharmony_ci "meta": { 10661cb0ef41Sopenharmony_ci "added": [ 10671cb0ef41Sopenharmony_ci "v0.1.21" 10681cb0ef41Sopenharmony_ci ], 10691cb0ef41Sopenharmony_ci "changes": [ 10701cb0ef41Sopenharmony_ci { 10711cb0ef41Sopenharmony_ci "version": "v10.0.0", 10721cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/17003", 10731cb0ef41Sopenharmony_ci "description": "Used comparison changed from Strict Equality to `Object.is()`." 10741cb0ef41Sopenharmony_ci } 10751cb0ef41Sopenharmony_ci ] 10761cb0ef41Sopenharmony_ci }, 10771cb0ef41Sopenharmony_ci "signatures": [ 10781cb0ef41Sopenharmony_ci { 10791cb0ef41Sopenharmony_ci "params": [ 10801cb0ef41Sopenharmony_ci { 10811cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 10821cb0ef41Sopenharmony_ci "name": "actual", 10831cb0ef41Sopenharmony_ci "type": "any" 10841cb0ef41Sopenharmony_ci }, 10851cb0ef41Sopenharmony_ci { 10861cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 10871cb0ef41Sopenharmony_ci "name": "expected", 10881cb0ef41Sopenharmony_ci "type": "any" 10891cb0ef41Sopenharmony_ci }, 10901cb0ef41Sopenharmony_ci { 10911cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 10921cb0ef41Sopenharmony_ci "name": "message", 10931cb0ef41Sopenharmony_ci "type": "string|Error" 10941cb0ef41Sopenharmony_ci } 10951cb0ef41Sopenharmony_ci ] 10961cb0ef41Sopenharmony_ci } 10971cb0ef41Sopenharmony_ci ], 10981cb0ef41Sopenharmony_ci "desc": "<p>Tests strict inequality between the <code>actual</code> and <code>expected</code> parameters as\ndetermined by <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\"><code>Object.is()</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.notStrictEqual(1, 2);\n// OK\n\nassert.notStrictEqual(1, 1);\n// AssertionError [ERR_ASSERTION]: Expected \"actual\" to be strictly unequal to:\n//\n// 1\n\nassert.notStrictEqual(1, '1');\n// OK\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.notStrictEqual(1, 2);\n// OK\n\nassert.notStrictEqual(1, 1);\n// AssertionError [ERR_ASSERTION]: Expected \"actual\" to be strictly unequal to:\n//\n// 1\n\nassert.notStrictEqual(1, '1');\n// OK\n</code></pre>\n<p>If the values are strictly equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned. If the\n<code>message</code> parameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown\ninstead of the <code>AssertionError</code>.</p>" 10991cb0ef41Sopenharmony_ci }, 11001cb0ef41Sopenharmony_ci { 11011cb0ef41Sopenharmony_ci "textRaw": "`assert.ok(value[, message])`", 11021cb0ef41Sopenharmony_ci "type": "method", 11031cb0ef41Sopenharmony_ci "name": "ok", 11041cb0ef41Sopenharmony_ci "meta": { 11051cb0ef41Sopenharmony_ci "added": [ 11061cb0ef41Sopenharmony_ci "v0.1.21" 11071cb0ef41Sopenharmony_ci ], 11081cb0ef41Sopenharmony_ci "changes": [ 11091cb0ef41Sopenharmony_ci { 11101cb0ef41Sopenharmony_ci "version": "v10.0.0", 11111cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/18319", 11121cb0ef41Sopenharmony_ci "description": "The `assert.ok()` (no arguments) will now use a predefined error message." 11131cb0ef41Sopenharmony_ci } 11141cb0ef41Sopenharmony_ci ] 11151cb0ef41Sopenharmony_ci }, 11161cb0ef41Sopenharmony_ci "signatures": [ 11171cb0ef41Sopenharmony_ci { 11181cb0ef41Sopenharmony_ci "params": [ 11191cb0ef41Sopenharmony_ci { 11201cb0ef41Sopenharmony_ci "textRaw": "`value` {any}", 11211cb0ef41Sopenharmony_ci "name": "value", 11221cb0ef41Sopenharmony_ci "type": "any" 11231cb0ef41Sopenharmony_ci }, 11241cb0ef41Sopenharmony_ci { 11251cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 11261cb0ef41Sopenharmony_ci "name": "message", 11271cb0ef41Sopenharmony_ci "type": "string|Error" 11281cb0ef41Sopenharmony_ci } 11291cb0ef41Sopenharmony_ci ] 11301cb0ef41Sopenharmony_ci } 11311cb0ef41Sopenharmony_ci ], 11321cb0ef41Sopenharmony_ci "desc": "<p>Tests if <code>value</code> is truthy. It is equivalent to\n<code>assert.equal(!!value, true, message)</code>.</p>\n<p>If <code>value</code> is not truthy, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a <code>message</code>\nproperty set equal to the value of the <code>message</code> parameter. If the <code>message</code>\nparameter is <code>undefined</code>, a default error message is assigned. If the <code>message</code>\nparameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown instead of the\n<code>AssertionError</code>.\nIf no arguments are passed in at all <code>message</code> will be set to the string:\n<code>'No value argument passed to `assert.ok()`'</code>.</p>\n<p>Be aware that in the <code>repl</code> the error message will be different to the one\nthrown in a file! See below for further details.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.ok(true);\n// OK\nassert.ok(1);\n// OK\n\nassert.ok();\n// AssertionError: No value argument passed to `assert.ok()`\n\nassert.ok(false, 'it\\'s false');\n// AssertionError: it's false\n\n// In the repl:\nassert.ok(typeof 123 === 'string');\n// AssertionError: false == true\n\n// In a file (e.g. test.js):\nassert.ok(typeof 123 === 'string');\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(typeof 123 === 'string')\n\nassert.ok(false);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(false)\n\nassert.ok(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(0)\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.ok(true);\n// OK\nassert.ok(1);\n// OK\n\nassert.ok();\n// AssertionError: No value argument passed to `assert.ok()`\n\nassert.ok(false, 'it\\'s false');\n// AssertionError: it's false\n\n// In the repl:\nassert.ok(typeof 123 === 'string');\n// AssertionError: false == true\n\n// In a file (e.g. test.js):\nassert.ok(typeof 123 === 'string');\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(typeof 123 === 'string')\n\nassert.ok(false);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(false)\n\nassert.ok(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert.ok(0)\n</code></pre>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\n// Using `assert()` works the same:\nassert(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert(0)\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert');\n\n// Using `assert()` works the same:\nassert(0);\n// AssertionError: The expression evaluated to a falsy value:\n//\n// assert(0)\n</code></pre>" 11331cb0ef41Sopenharmony_ci }, 11341cb0ef41Sopenharmony_ci { 11351cb0ef41Sopenharmony_ci "textRaw": "`assert.rejects(asyncFn[, error][, message])`", 11361cb0ef41Sopenharmony_ci "type": "method", 11371cb0ef41Sopenharmony_ci "name": "rejects", 11381cb0ef41Sopenharmony_ci "meta": { 11391cb0ef41Sopenharmony_ci "added": [ 11401cb0ef41Sopenharmony_ci "v10.0.0" 11411cb0ef41Sopenharmony_ci ], 11421cb0ef41Sopenharmony_ci "changes": [] 11431cb0ef41Sopenharmony_ci }, 11441cb0ef41Sopenharmony_ci "signatures": [ 11451cb0ef41Sopenharmony_ci { 11461cb0ef41Sopenharmony_ci "params": [ 11471cb0ef41Sopenharmony_ci { 11481cb0ef41Sopenharmony_ci "textRaw": "`asyncFn` {Function|Promise}", 11491cb0ef41Sopenharmony_ci "name": "asyncFn", 11501cb0ef41Sopenharmony_ci "type": "Function|Promise" 11511cb0ef41Sopenharmony_ci }, 11521cb0ef41Sopenharmony_ci { 11531cb0ef41Sopenharmony_ci "textRaw": "`error` {RegExp|Function|Object|Error}", 11541cb0ef41Sopenharmony_ci "name": "error", 11551cb0ef41Sopenharmony_ci "type": "RegExp|Function|Object|Error" 11561cb0ef41Sopenharmony_ci }, 11571cb0ef41Sopenharmony_ci { 11581cb0ef41Sopenharmony_ci "textRaw": "`message` {string}", 11591cb0ef41Sopenharmony_ci "name": "message", 11601cb0ef41Sopenharmony_ci "type": "string" 11611cb0ef41Sopenharmony_ci } 11621cb0ef41Sopenharmony_ci ] 11631cb0ef41Sopenharmony_ci } 11641cb0ef41Sopenharmony_ci ], 11651cb0ef41Sopenharmony_ci "desc": "<p>Awaits the <code>asyncFn</code> promise or, if <code>asyncFn</code> is a function, immediately\ncalls the function and awaits the returned promise to complete. It will then\ncheck that the promise is rejected.</p>\n<p>If <code>asyncFn</code> is a function and it throws an error synchronously,\n<code>assert.rejects()</code> will return a rejected <code>Promise</code> with that error. If the\nfunction does not return a promise, <code>assert.rejects()</code> will return a rejected\n<code>Promise</code> with an <a href=\"errors.html#err_invalid_return_value\"><code>ERR_INVALID_RETURN_VALUE</code></a> error. In both cases the error\nhandler is skipped.</p>\n<p>Besides the async nature to await the completion behaves identically to\n<a href=\"#assertthrowsfn-error-message\"><code>assert.throws()</code></a>.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, a validation function,\nan object where each property will be tested for, or an instance of error where\neach property will be tested for including the non-enumerable <code>message</code> and\n<code>name</code> properties.</p>\n<p>If specified, <code>message</code> will be the message provided by the <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>\nif the <code>asyncFn</code> fails to reject.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nawait assert.rejects(\n async () => {\n throw new TypeError('Wrong value');\n },\n {\n name: 'TypeError',\n message: 'Wrong value',\n },\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\n(async () => {\n await assert.rejects(\n async () => {\n throw new TypeError('Wrong value');\n },\n {\n name: 'TypeError',\n message: 'Wrong value',\n },\n );\n})();\n</code></pre>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nawait assert.rejects(\n async () => {\n throw new TypeError('Wrong value');\n },\n (err) => {\n assert.strictEqual(err.name, 'TypeError');\n assert.strictEqual(err.message, 'Wrong value');\n return true;\n },\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\n(async () => {\n await assert.rejects(\n async () => {\n throw new TypeError('Wrong value');\n },\n (err) => {\n assert.strictEqual(err.name, 'TypeError');\n assert.strictEqual(err.message, 'Wrong value');\n return true;\n },\n );\n})();\n</code></pre>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.rejects(\n Promise.reject(new Error('Wrong value')),\n Error,\n).then(() => {\n // ...\n});\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.rejects(\n Promise.reject(new Error('Wrong value')),\n Error,\n).then(() => {\n // ...\n});\n</code></pre>\n<p><code>error</code> cannot be a string. If a string is provided as the second\nargument, then <code>error</code> is assumed to be omitted and the string will be used for\n<code>message</code> instead. This can lead to easy-to-miss mistakes. Please read the\nexample in <a href=\"#assertthrowsfn-error-message\"><code>assert.throws()</code></a> carefully if using a string as the second\nargument gets considered.</p>" 11661cb0ef41Sopenharmony_ci }, 11671cb0ef41Sopenharmony_ci { 11681cb0ef41Sopenharmony_ci "textRaw": "`assert.strictEqual(actual, expected[, message])`", 11691cb0ef41Sopenharmony_ci "type": "method", 11701cb0ef41Sopenharmony_ci "name": "strictEqual", 11711cb0ef41Sopenharmony_ci "meta": { 11721cb0ef41Sopenharmony_ci "added": [ 11731cb0ef41Sopenharmony_ci "v0.1.21" 11741cb0ef41Sopenharmony_ci ], 11751cb0ef41Sopenharmony_ci "changes": [ 11761cb0ef41Sopenharmony_ci { 11771cb0ef41Sopenharmony_ci "version": "v10.0.0", 11781cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/17003", 11791cb0ef41Sopenharmony_ci "description": "Used comparison changed from Strict Equality to `Object.is()`." 11801cb0ef41Sopenharmony_ci } 11811cb0ef41Sopenharmony_ci ] 11821cb0ef41Sopenharmony_ci }, 11831cb0ef41Sopenharmony_ci "signatures": [ 11841cb0ef41Sopenharmony_ci { 11851cb0ef41Sopenharmony_ci "params": [ 11861cb0ef41Sopenharmony_ci { 11871cb0ef41Sopenharmony_ci "textRaw": "`actual` {any}", 11881cb0ef41Sopenharmony_ci "name": "actual", 11891cb0ef41Sopenharmony_ci "type": "any" 11901cb0ef41Sopenharmony_ci }, 11911cb0ef41Sopenharmony_ci { 11921cb0ef41Sopenharmony_ci "textRaw": "`expected` {any}", 11931cb0ef41Sopenharmony_ci "name": "expected", 11941cb0ef41Sopenharmony_ci "type": "any" 11951cb0ef41Sopenharmony_ci }, 11961cb0ef41Sopenharmony_ci { 11971cb0ef41Sopenharmony_ci "textRaw": "`message` {string|Error}", 11981cb0ef41Sopenharmony_ci "name": "message", 11991cb0ef41Sopenharmony_ci "type": "string|Error" 12001cb0ef41Sopenharmony_ci } 12011cb0ef41Sopenharmony_ci ] 12021cb0ef41Sopenharmony_ci } 12031cb0ef41Sopenharmony_ci ], 12041cb0ef41Sopenharmony_ci "desc": "<p>Tests strict equality between the <code>actual</code> and <code>expected</code> parameters as\ndetermined by <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is\"><code>Object.is()</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.strictEqual(1, 2);\n// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:\n//\n// 1 !== 2\n\nassert.strictEqual(1, 1);\n// OK\n\nassert.strictEqual('Hello foobar', 'Hello World!');\n// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:\n// + actual - expected\n//\n// + 'Hello foobar'\n// - 'Hello World!'\n// ^\n\nconst apples = 1;\nconst oranges = 2;\nassert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);\n// AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2\n\nassert.strictEqual(1, '1', new TypeError('Inputs are not identical'));\n// TypeError: Inputs are not identical\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.strictEqual(1, 2);\n// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:\n//\n// 1 !== 2\n\nassert.strictEqual(1, 1);\n// OK\n\nassert.strictEqual('Hello foobar', 'Hello World!');\n// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal:\n// + actual - expected\n//\n// + 'Hello foobar'\n// - 'Hello World!'\n// ^\n\nconst apples = 1;\nconst oranges = 2;\nassert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`);\n// AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2\n\nassert.strictEqual(1, '1', new TypeError('Inputs are not identical'));\n// TypeError: Inputs are not identical\n</code></pre>\n<p>If the values are not strictly equal, an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a> is thrown with a\n<code>message</code> property set equal to the value of the <code>message</code> parameter. If the\n<code>message</code> parameter is undefined, a default error message is assigned. If the\n<code>message</code> parameter is an instance of an <a href=\"errors.html#class-error\"><code>Error</code></a> then it will be thrown\ninstead of the <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>" 12051cb0ef41Sopenharmony_ci }, 12061cb0ef41Sopenharmony_ci { 12071cb0ef41Sopenharmony_ci "textRaw": "`assert.throws(fn[, error][, message])`", 12081cb0ef41Sopenharmony_ci "type": "method", 12091cb0ef41Sopenharmony_ci "name": "throws", 12101cb0ef41Sopenharmony_ci "meta": { 12111cb0ef41Sopenharmony_ci "added": [ 12121cb0ef41Sopenharmony_ci "v0.1.21" 12131cb0ef41Sopenharmony_ci ], 12141cb0ef41Sopenharmony_ci "changes": [ 12151cb0ef41Sopenharmony_ci { 12161cb0ef41Sopenharmony_ci "version": "v10.2.0", 12171cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/20485", 12181cb0ef41Sopenharmony_ci "description": "The `error` parameter can be an object containing regular expressions now." 12191cb0ef41Sopenharmony_ci }, 12201cb0ef41Sopenharmony_ci { 12211cb0ef41Sopenharmony_ci "version": "v9.9.0", 12221cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/17584", 12231cb0ef41Sopenharmony_ci "description": "The `error` parameter can now be an object as well." 12241cb0ef41Sopenharmony_ci }, 12251cb0ef41Sopenharmony_ci { 12261cb0ef41Sopenharmony_ci "version": "v4.2.0", 12271cb0ef41Sopenharmony_ci "pr-url": "https://github.com/nodejs/node/pull/3276", 12281cb0ef41Sopenharmony_ci "description": "The `error` parameter can now be an arrow function." 12291cb0ef41Sopenharmony_ci } 12301cb0ef41Sopenharmony_ci ] 12311cb0ef41Sopenharmony_ci }, 12321cb0ef41Sopenharmony_ci "signatures": [ 12331cb0ef41Sopenharmony_ci { 12341cb0ef41Sopenharmony_ci "params": [ 12351cb0ef41Sopenharmony_ci { 12361cb0ef41Sopenharmony_ci "textRaw": "`fn` {Function}", 12371cb0ef41Sopenharmony_ci "name": "fn", 12381cb0ef41Sopenharmony_ci "type": "Function" 12391cb0ef41Sopenharmony_ci }, 12401cb0ef41Sopenharmony_ci { 12411cb0ef41Sopenharmony_ci "textRaw": "`error` {RegExp|Function|Object|Error}", 12421cb0ef41Sopenharmony_ci "name": "error", 12431cb0ef41Sopenharmony_ci "type": "RegExp|Function|Object|Error" 12441cb0ef41Sopenharmony_ci }, 12451cb0ef41Sopenharmony_ci { 12461cb0ef41Sopenharmony_ci "textRaw": "`message` {string}", 12471cb0ef41Sopenharmony_ci "name": "message", 12481cb0ef41Sopenharmony_ci "type": "string" 12491cb0ef41Sopenharmony_ci } 12501cb0ef41Sopenharmony_ci ] 12511cb0ef41Sopenharmony_ci } 12521cb0ef41Sopenharmony_ci ], 12531cb0ef41Sopenharmony_ci "desc": "<p>Expects the function <code>fn</code> to throw an error.</p>\n<p>If specified, <code>error</code> can be a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes\"><code>Class</code></a>, <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>, a validation function,\na validation object where each property will be tested for strict deep equality,\nor an instance of error where each property will be tested for strict deep\nequality including the non-enumerable <code>message</code> and <code>name</code> properties. When\nusing an object, it is also possible to use a regular expression, when\nvalidating against a string property. See below for examples.</p>\n<p>If specified, <code>message</code> will be appended to the message provided by the\n<code>AssertionError</code> if the <code>fn</code> call fails to throw or in case the error validation\nfails.</p>\n<p>Custom validation object/error instance:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nconst err = new TypeError('Wrong value');\nerr.code = 404;\nerr.foo = 'bar';\nerr.info = {\n nested: true,\n baz: 'text',\n};\nerr.reg = /abc/i;\n\nassert.throws(\n () => {\n throw err;\n },\n {\n name: 'TypeError',\n message: 'Wrong value',\n info: {\n nested: true,\n baz: 'text',\n },\n // Only properties on the validation object will be tested for.\n // Using nested objects requires all properties to be present. Otherwise\n // the validation is going to fail.\n },\n);\n\n// Using regular expressions to validate error properties:\nassert.throws(\n () => {\n throw err;\n },\n {\n // The `name` and `message` properties are strings and using regular\n // expressions on those will match against the string. If they fail, an\n // error is thrown.\n name: /^TypeError$/,\n message: /Wrong/,\n foo: 'bar',\n info: {\n nested: true,\n // It is not possible to use regular expressions for nested properties!\n baz: 'text',\n },\n // The `reg` property contains a regular expression and only if the\n // validation object contains an identical regular expression, it is going\n // to pass.\n reg: /abc/i,\n },\n);\n\n// Fails due to the different `message` and `name` properties:\nassert.throws(\n () => {\n const otherErr = new Error('Not found');\n // Copy all enumerable properties from `err` to `otherErr`.\n for (const [key, value] of Object.entries(err)) {\n otherErr[key] = value;\n }\n throw otherErr;\n },\n // The error's `message` and `name` properties will also be checked when using\n // an error as validation object.\n err,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nconst err = new TypeError('Wrong value');\nerr.code = 404;\nerr.foo = 'bar';\nerr.info = {\n nested: true,\n baz: 'text',\n};\nerr.reg = /abc/i;\n\nassert.throws(\n () => {\n throw err;\n },\n {\n name: 'TypeError',\n message: 'Wrong value',\n info: {\n nested: true,\n baz: 'text',\n },\n // Only properties on the validation object will be tested for.\n // Using nested objects requires all properties to be present. Otherwise\n // the validation is going to fail.\n },\n);\n\n// Using regular expressions to validate error properties:\nassert.throws(\n () => {\n throw err;\n },\n {\n // The `name` and `message` properties are strings and using regular\n // expressions on those will match against the string. If they fail, an\n // error is thrown.\n name: /^TypeError$/,\n message: /Wrong/,\n foo: 'bar',\n info: {\n nested: true,\n // It is not possible to use regular expressions for nested properties!\n baz: 'text',\n },\n // The `reg` property contains a regular expression and only if the\n // validation object contains an identical regular expression, it is going\n // to pass.\n reg: /abc/i,\n },\n);\n\n// Fails due to the different `message` and `name` properties:\nassert.throws(\n () => {\n const otherErr = new Error('Not found');\n // Copy all enumerable properties from `err` to `otherErr`.\n for (const [key, value] of Object.entries(err)) {\n otherErr[key] = value;\n }\n throw otherErr;\n },\n // The error's `message` and `name` properties will also be checked when using\n // an error as validation object.\n err,\n);\n</code></pre>\n<p>Validate instanceof using constructor:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n Error,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n Error,\n);\n</code></pre>\n<p>Validate error message using <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions\"><code>RegExp</code></a>:</p>\n<p>Using a regular expression runs <code>.toString</code> on the error object, and will\ntherefore also include the error name.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n /^Error: Wrong value$/,\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n /^Error: Wrong value$/,\n);\n</code></pre>\n<p>Custom error validation:</p>\n<p>The function must return <code>true</code> to indicate all internal validations passed.\nIt will otherwise fail with an <a href=\"#class-assertassertionerror\"><code>AssertionError</code></a>.</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n (err) => {\n assert(err instanceof Error);\n assert(/value/.test(err));\n // Avoid returning anything from validation functions besides `true`.\n // Otherwise, it's not clear what part of the validation failed. Instead,\n // throw an error about the specific validation that failed (as done in this\n // example) and add as much helpful debugging information to that error as\n // possible.\n return true;\n },\n 'unexpected error',\n);\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nassert.throws(\n () => {\n throw new Error('Wrong value');\n },\n (err) => {\n assert(err instanceof Error);\n assert(/value/.test(err));\n // Avoid returning anything from validation functions besides `true`.\n // Otherwise, it's not clear what part of the validation failed. Instead,\n // throw an error about the specific validation that failed (as done in this\n // example) and add as much helpful debugging information to that error as\n // possible.\n return true;\n },\n 'unexpected error',\n);\n</code></pre>\n<p><code>error</code> cannot be a string. If a string is provided as the second\nargument, then <code>error</code> is assumed to be omitted and the string will be used for\n<code>message</code> instead. This can lead to easy-to-miss mistakes. Using the same\nmessage as the thrown error message is going to result in an\n<code>ERR_AMBIGUOUS_ARGUMENT</code> error. Please read the example below carefully if using\na string as the second argument gets considered:</p>\n<pre><code class=\"language-mjs\">import assert from 'node:assert/strict';\n\nfunction throwingFirst() {\n throw new Error('First');\n}\n\nfunction throwingSecond() {\n throw new Error('Second');\n}\n\nfunction notThrowing() {}\n\n// The second argument is a string and the input function threw an Error.\n// The first case will not throw as it does not match for the error message\n// thrown by the input function!\nassert.throws(throwingFirst, 'Second');\n// In the next example the message has no benefit over the message from the\n// error and since it is not clear if the user intended to actually match\n// against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.\nassert.throws(throwingSecond, 'Second');\n// TypeError [ERR_AMBIGUOUS_ARGUMENT]\n\n// The string is only used (as message) in case the function does not throw:\nassert.throws(notThrowing, 'Second');\n// AssertionError [ERR_ASSERTION]: Missing expected exception: Second\n\n// If it was intended to match for the error message do this instead:\n// It does not throw because the error messages match.\nassert.throws(throwingSecond, /Second$/);\n\n// If the error message does not match, an AssertionError is thrown.\nassert.throws(throwingFirst, /Second$/);\n// AssertionError [ERR_ASSERTION]\n</code></pre>\n<pre><code class=\"language-cjs\">const assert = require('node:assert/strict');\n\nfunction throwingFirst() {\n throw new Error('First');\n}\n\nfunction throwingSecond() {\n throw new Error('Second');\n}\n\nfunction notThrowing() {}\n\n// The second argument is a string and the input function threw an Error.\n// The first case will not throw as it does not match for the error message\n// thrown by the input function!\nassert.throws(throwingFirst, 'Second');\n// In the next example the message has no benefit over the message from the\n// error and since it is not clear if the user intended to actually match\n// against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error.\nassert.throws(throwingSecond, 'Second');\n// TypeError [ERR_AMBIGUOUS_ARGUMENT]\n\n// The string is only used (as message) in case the function does not throw:\nassert.throws(notThrowing, 'Second');\n// AssertionError [ERR_ASSERTION]: Missing expected exception: Second\n\n// If it was intended to match for the error message do this instead:\n// It does not throw because the error messages match.\nassert.throws(throwingSecond, /Second$/);\n\n// If the error message does not match, an AssertionError is thrown.\nassert.throws(throwingFirst, /Second$/);\n// AssertionError [ERR_ASSERTION]\n</code></pre>\n<p>Due to the confusing error-prone notation, avoid a string as the second\nargument.</p>" 12541cb0ef41Sopenharmony_ci } 12551cb0ef41Sopenharmony_ci ], 12561cb0ef41Sopenharmony_ci "type": "module", 12571cb0ef41Sopenharmony_ci "displayName": "Assert" 12581cb0ef41Sopenharmony_ci } 12591cb0ef41Sopenharmony_ci ] 12601cb0ef41Sopenharmony_ci}