1# Assert 2 3<!--introduced_in=v0.1.21--> 4 5> Stability: 2 - Stable 6 7<!-- source_link=lib/assert.js --> 8 9The `assert` module provides a set of assertion functions for verifying 10invariants. 11 12## Strict assertion mode 13<!-- YAML 14added: v9.9.0 15changes: 16 - version: v12.16.2 17 description: Changed "strict mode" to "strict assertion mode" and "legacy 18 mode" to "legacy assertion mode" to avoid confusion with the 19 more usual meaning of "strict mode". 20 - version: v9.9.0 21 pr-url: https://github.com/nodejs/node/pull/17615 22 description: Added error diffs to the strict assertion mode. 23 - version: v9.9.0 24 pr-url: https://github.com/nodejs/node/pull/17002 25 description: Added strict assertion mode to the assert module. 26--> 27 28In strict assertion mode, non-strict methods behave like their corresponding 29strict methods. For example, [`assert.deepEqual()`][] will behave like 30[`assert.deepStrictEqual()`][]. 31 32In strict assertion mode, error messages for objects display a diff. In legacy 33assertion mode, error messages for objects display the objects, often truncated. 34 35To use strict assertion mode: 36 37```js 38const assert = require('assert').strict; 39``` 40 41Example error diff: 42 43```js 44const assert = require('assert').strict; 45 46assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]); 47// AssertionError: Expected inputs to be strictly deep-equal: 48// + actual - expected ... Lines skipped 49// 50// [ 51// [ 52// ... 53// 2, 54// + 3 55// - '3' 56// ], 57// ... 58// 5 59// ] 60``` 61 62To deactivate the colors, use the `NO_COLOR` or `NODE_DISABLE_COLORS` 63environment variables. This will also deactivate the colors in the REPL. For 64more on color support in terminal environments, read the tty 65[getColorDepth()](tty.html#tty_writestream_getcolordepth_env) documentation. 66 67## Legacy assertion mode 68 69Legacy assertion mode uses the [Abstract Equality Comparison][] in: 70 71* [`assert.deepEqual()`][] 72* [`assert.equal()`][] 73* [`assert.notDeepEqual()`][] 74* [`assert.notEqual()`][] 75 76To use legacy assertion mode: 77 78```js 79const assert = require('assert'); 80``` 81 82Whenever possible, use the [strict assertion mode][] instead. Otherwise, the 83[Abstract Equality Comparison][] may cause surprising results. This is 84especially true for [`assert.deepEqual()`][], where the comparison rules are 85lax: 86 87```js 88// WARNING: This does not throw an AssertionError! 89assert.deepEqual(/a/gi, new Date()); 90``` 91 92## Class: assert.AssertionError 93 94* Extends: {errors.Error} 95 96Indicates the failure of an assertion. All errors thrown by the `assert` module 97will be instances of the `AssertionError` class. 98 99### `new assert.AssertionError(options)` 100<!-- YAML 101added: v0.1.21 102--> 103 104* `options` {Object} 105 * `message` {string} If provided, the error message is set to this value. 106 * `actual` {any} The `actual` property on the error instance. 107 * `expected` {any} The `expected` property on the error instance. 108 * `operator` {string} The `operator` property on the error instance. 109 * `stackStartFn` {Function} If provided, the generated stack trace omits 110 frames before this function. 111 112A subclass of `Error` that indicates the failure of an assertion. 113 114All instances contain the built-in `Error` properties (`message` and `name`) 115and: 116 117* `actual` {any} Set to the `actual` argument for methods such as 118 [`assert.strictEqual()`][]. 119* `expected` {any} Set to the `expected` value for methods such as 120 [`assert.strictEqual()`][]. 121* `generatedMessage` {boolean} Indicates if the message was auto-generated 122 (`true`) or not. 123* `code` {string} Value is always `ERR_ASSERTION` to show that the error is an 124 assertion error. 125* `operator` {string} Set to the passed in operator value. 126 127```js 128const assert = require('assert'); 129 130// Generate an AssertionError to compare the error message later: 131const { message } = new assert.AssertionError({ 132 actual: 1, 133 expected: 2, 134 operator: 'strictEqual' 135}); 136 137// Verify error output: 138try { 139 assert.strictEqual(1, 2); 140} catch (err) { 141 assert(err instanceof assert.AssertionError); 142 assert.strictEqual(err.message, message); 143 assert.strictEqual(err.name, 'AssertionError'); 144 assert.strictEqual(err.actual, 1); 145 assert.strictEqual(err.expected, 2); 146 assert.strictEqual(err.code, 'ERR_ASSERTION'); 147 assert.strictEqual(err.operator, 'strictEqual'); 148 assert.strictEqual(err.generatedMessage, true); 149} 150``` 151 152## Class: `assert.CallTracker` 153<!-- YAML 154added: v12.19.0 155--> 156 157> Stability: 1 - Experimental 158 159This feature is currently experimental and behavior might still change. 160 161### `new assert.CallTracker()` 162<!-- YAML 163added: v12.19.0 164--> 165 166Creates a new [`CallTracker`][] object which can be used to track if functions 167were called a specific number of times. The `tracker.verify()` must be called 168for the verification to take place. The usual pattern would be to call it in a 169[`process.on('exit')`][] handler. 170 171```js 172const assert = require('assert'); 173 174const tracker = new assert.CallTracker(); 175 176function func() {} 177 178// callsfunc() must be called exactly 1 time before tracker.verify(). 179const callsfunc = tracker.calls(func, 1); 180 181callsfunc(); 182 183// Calls tracker.verify() and verifies if all tracker.calls() functions have 184// been called exact times. 185process.on('exit', () => { 186 tracker.verify(); 187}); 188``` 189 190### `tracker.calls([fn][, exact])` 191<!-- YAML 192added: v12.19.0 193--> 194 195* `fn` {Function} **Default** A no-op function. 196* `exact` {number} **Default** `1`. 197* Returns: {Function} that wraps `fn`. 198 199The wrapper function is expected to be called exactly `exact` times. If the 200function has not been called exactly `exact` times when 201[`tracker.verify()`][] is called, then [`tracker.verify()`][] will throw an 202error. 203 204```js 205const assert = require('assert'); 206 207// Creates call tracker. 208const tracker = new assert.CallTracker(); 209 210function func() {} 211 212// Returns a function that wraps func() that must be called exact times 213// before tracker.verify(). 214const callsfunc = tracker.calls(func); 215``` 216 217### `tracker.report()` 218<!-- YAML 219added: v12.19.0 220--> 221 222* Returns: {Array} of objects containing information about the wrapper functions 223returned by [`tracker.calls()`][]. 224* Object {Object} 225 * `message` {string} 226 * `actual` {number} The actual number of times the function was called. 227 * `expected` {number} The number of times the function was expected to be 228 called. 229 * `operator` {string} The name of the function that is wrapped. 230 * `stack` {Object} A stack trace of the function. 231 232The arrays contains information about the expected and actual number of calls of 233the functions that have not been called the expected number of times. 234 235```js 236const assert = require('assert'); 237 238// Creates call tracker. 239const tracker = new assert.CallTracker(); 240 241function func() {} 242 243function foo() {} 244 245// Returns a function that wraps func() that must be called exact times 246// before tracker.verify(). 247const callsfunc = tracker.calls(func, 2); 248 249// Returns an array containing information on callsfunc() 250tracker.report(); 251// [ 252// { 253// message: 'Expected the func function to be executed 2 time(s) but was 254// executed 0 time(s).', 255// actual: 0, 256// expected: 2, 257// operator: 'func', 258// stack: stack trace 259// } 260// ] 261``` 262 263### `tracker.verify()` 264<!-- YAML 265added: v12.19.0 266--> 267 268Iterates through the list of functions passed to 269[`tracker.calls()`][] and will throw an error for functions that 270have not been called the expected number of times. 271 272```js 273const assert = require('assert'); 274 275// Creates call tracker. 276const tracker = new assert.CallTracker(); 277 278function func() {} 279 280// Returns a function that wraps func() that must be called exact times 281// before tracker.verify(). 282const callsfunc = tracker.calls(func, 2); 283 284callsfunc(); 285 286// Will throw an error since callsfunc() was only called once. 287tracker.verify(); 288``` 289 290## `assert(value[, message])` 291<!-- YAML 292added: v0.5.9 293--> 294 295* `value` {any} The input that is checked for being truthy. 296* `message` {string|Error} 297 298An alias of [`assert.ok()`][]. 299 300## `assert.deepEqual(actual, expected[, message])` 301<!-- YAML 302added: v0.1.21 303changes: 304 - version: v12.0.0 305 pr-url: https://github.com/nodejs/node/pull/25008 306 description: The type tags are now properly compared and there are a couple 307 minor comparison adjustments to make the check less surprising. 308 - version: v9.0.0 309 pr-url: https://github.com/nodejs/node/pull/15001 310 description: The `Error` names and messages are now properly compared 311 - version: v8.0.0 312 pr-url: https://github.com/nodejs/node/pull/12142 313 description: The `Set` and `Map` content is also compared 314 - version: v6.4.0, v4.7.1 315 pr-url: https://github.com/nodejs/node/pull/8002 316 description: Typed array slices are handled correctly now. 317 - version: v6.1.0, v4.5.0 318 pr-url: https://github.com/nodejs/node/pull/6432 319 description: Objects with circular references can be used as inputs now. 320 - version: v5.10.1, v4.4.3 321 pr-url: https://github.com/nodejs/node/pull/5910 322 description: Handle non-`Uint8Array` typed arrays correctly. 323--> 324 325* `actual` {any} 326* `expected` {any} 327* `message` {string|Error} 328 329**Strict assertion mode** 330 331An alias of [`assert.deepStrictEqual()`][]. 332 333**Legacy assertion mode** 334 335> Stability: 0 - Deprecated: Use [`assert.deepStrictEqual()`][] instead. 336 337Tests for deep equality between the `actual` and `expected` parameters. Consider 338using [`assert.deepStrictEqual()`][] instead. [`assert.deepEqual()`][] can have 339surprising results. 340 341_Deep equality_ means that the enumerable "own" properties of child objects 342are also recursively evaluated by the following rules. 343 344### Comparison details 345 346* Primitive values are compared with the [Abstract Equality Comparison][] 347 ( `==` ). 348* [Type tags][Object.prototype.toString()] of objects should be the same. 349* Only [enumerable "own" properties][] are considered. 350* [`Error`][] names and messages are always compared, even if these are not 351 enumerable properties. 352* [Object wrappers][] are compared both as objects and unwrapped values. 353* `Object` properties are compared unordered. 354* [`Map`][] keys and [`Set`][] items are compared unordered. 355* Recursion stops when both sides differ or both sides encounter a circular 356 reference. 357* Implementation does not test the [`[[Prototype]]`][prototype-spec] of 358 objects. 359* [`Symbol`][] properties are not compared. 360* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. 361 362The following example does not throw an [`AssertionError`][] because the 363primitives are considered equal by the [Abstract Equality Comparison][] 364( `==` ). 365 366```js 367// WARNING: This does not throw an AssertionError! 368assert.deepEqual('+00000000', false); 369``` 370 371"Deep" equality means that the enumerable "own" properties of child objects 372are evaluated also: 373 374```js 375const assert = require('assert'); 376 377const obj1 = { 378 a: { 379 b: 1 380 } 381}; 382const obj2 = { 383 a: { 384 b: 2 385 } 386}; 387const obj3 = { 388 a: { 389 b: 1 390 } 391}; 392const obj4 = Object.create(obj1); 393 394assert.deepEqual(obj1, obj1); 395// OK 396 397// Values of b are different: 398assert.deepEqual(obj1, obj2); 399// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } } 400 401assert.deepEqual(obj1, obj3); 402// OK 403 404// Prototypes are ignored: 405assert.deepEqual(obj1, obj4); 406// AssertionError: { a: { b: 1 } } deepEqual {} 407``` 408 409If the values are not equal, an [`AssertionError`][] is thrown with a `message` 410property set equal to the value of the `message` parameter. If the `message` 411parameter is undefined, a default error message is assigned. If the `message` 412parameter is an instance of an [`Error`][] then it will be thrown instead of the 413[`AssertionError`][]. 414 415## `assert.deepStrictEqual(actual, expected[, message])` 416<!-- YAML 417added: v1.2.0 418changes: 419 - version: v9.0.0 420 pr-url: https://github.com/nodejs/node/pull/15169 421 description: Enumerable symbol properties are now compared. 422 - version: v9.0.0 423 pr-url: https://github.com/nodejs/node/pull/15036 424 description: The `NaN` is now compared using the 425 [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) 426 comparison. 427 - version: v8.5.0 428 pr-url: https://github.com/nodejs/node/pull/15001 429 description: The `Error` names and messages are now properly compared 430 - version: v8.0.0 431 pr-url: https://github.com/nodejs/node/pull/12142 432 description: The `Set` and `Map` content is also compared 433 - version: v6.4.0, v4.7.1 434 pr-url: https://github.com/nodejs/node/pull/8002 435 description: Typed array slices are handled correctly now. 436 - version: v6.1.0 437 pr-url: https://github.com/nodejs/node/pull/6432 438 description: Objects with circular references can be used as inputs now. 439 - version: v5.10.1, v4.4.3 440 pr-url: https://github.com/nodejs/node/pull/5910 441 description: Handle non-`Uint8Array` typed arrays correctly. 442--> 443 444* `actual` {any} 445* `expected` {any} 446* `message` {string|Error} 447 448Tests for deep equality between the `actual` and `expected` parameters. 449"Deep" equality means that the enumerable "own" properties of child objects 450are recursively evaluated also by the following rules. 451 452### Comparison details 453 454* Primitive values are compared using the [SameValue Comparison][], used by 455 [`Object.is()`][]. 456* [Type tags][Object.prototype.toString()] of objects should be the same. 457* [`[[Prototype]]`][prototype-spec] of objects are compared using 458 the [Strict Equality Comparison][]. 459* Only [enumerable "own" properties][] are considered. 460* [`Error`][] names and messages are always compared, even if these are not 461 enumerable properties. 462* Enumerable own [`Symbol`][] properties are compared as well. 463* [Object wrappers][] are compared both as objects and unwrapped values. 464* `Object` properties are compared unordered. 465* [`Map`][] keys and [`Set`][] items are compared unordered. 466* Recursion stops when both sides differ or both sides encounter a circular 467 reference. 468* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See 469 below for further details. 470 471```js 472const assert = require('assert').strict; 473 474// This fails because 1 !== '1'. 475assert.deepStrictEqual({ a: 1 }, { a: '1' }); 476// AssertionError: Expected inputs to be strictly deep-equal: 477// + actual - expected 478// 479// { 480// + a: 1 481// - a: '1' 482// } 483 484// The following objects don't have own properties 485const date = new Date(); 486const object = {}; 487const fakeDate = {}; 488Object.setPrototypeOf(fakeDate, Date.prototype); 489 490// Different [[Prototype]]: 491assert.deepStrictEqual(object, fakeDate); 492// AssertionError: Expected inputs to be strictly deep-equal: 493// + actual - expected 494// 495// + {} 496// - Date {} 497 498// Different type tags: 499assert.deepStrictEqual(date, fakeDate); 500// AssertionError: Expected inputs to be strictly deep-equal: 501// + actual - expected 502// 503// + 2018-04-26T00:49:08.604Z 504// - Date {} 505 506assert.deepStrictEqual(NaN, NaN); 507// OK, because of the SameValue comparison 508 509// Different unwrapped numbers: 510assert.deepStrictEqual(new Number(1), new Number(2)); 511// AssertionError: Expected inputs to be strictly deep-equal: 512// + actual - expected 513// 514// + [Number: 1] 515// - [Number: 2] 516 517assert.deepStrictEqual(new String('foo'), Object('foo')); 518// OK because the object and the string are identical when unwrapped. 519 520assert.deepStrictEqual(-0, -0); 521// OK 522 523// Different zeros using the SameValue Comparison: 524assert.deepStrictEqual(0, -0); 525// AssertionError: Expected inputs to be strictly deep-equal: 526// + actual - expected 527// 528// + 0 529// - -0 530 531const symbol1 = Symbol(); 532const symbol2 = Symbol(); 533assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol1]: 1 }); 534// OK, because it is the same symbol on both objects. 535 536assert.deepStrictEqual({ [symbol1]: 1 }, { [symbol2]: 1 }); 537// AssertionError [ERR_ASSERTION]: Inputs identical but not reference equal: 538// 539// { 540// [Symbol()]: 1 541// } 542 543const weakMap1 = new WeakMap(); 544const weakMap2 = new WeakMap([[{}, {}]]); 545const weakMap3 = new WeakMap(); 546weakMap3.unequal = true; 547 548assert.deepStrictEqual(weakMap1, weakMap2); 549// OK, because it is impossible to compare the entries 550 551// Fails because weakMap3 has a property that weakMap1 does not contain: 552assert.deepStrictEqual(weakMap1, weakMap3); 553// AssertionError: Expected inputs to be strictly deep-equal: 554// + actual - expected 555// 556// WeakMap { 557// + [items unknown] 558// - [items unknown], 559// - unequal: true 560// } 561``` 562 563If the values are not equal, an [`AssertionError`][] is thrown with a `message` 564property set equal to the value of the `message` parameter. If the `message` 565parameter is undefined, a default error message is assigned. If the `message` 566parameter is an instance of an [`Error`][] then it will be thrown instead of the 567`AssertionError`. 568 569## `assert.doesNotMatch(string, regexp[, message])` 570<!-- YAML 571added: v12.16.0 572--> 573 574* `string` {string} 575* `regexp` {RegExp} 576* `message` {string|Error} 577 578> Stability: 1 - Experimental 579 580Expects the `string` input not to match the regular expression. 581 582This feature is currently experimental and the name might change or it might be 583completely removed again. 584 585```js 586const assert = require('assert').strict; 587 588assert.doesNotMatch('I will fail', /fail/); 589// AssertionError [ERR_ASSERTION]: The input was expected to not match the ... 590 591assert.doesNotMatch(123, /pass/); 592// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string. 593 594assert.doesNotMatch('I will pass', /different/); 595// OK 596``` 597 598If the values do match, or if the `string` argument is of another type than 599`string`, an [`AssertionError`][] is thrown with a `message` property set equal 600to the value of the `message` parameter. If the `message` parameter is 601undefined, a default error message is assigned. If the `message` parameter is an 602instance of an [`Error`][] then it will be thrown instead of the 603[`AssertionError`][]. 604 605## `assert.doesNotReject(asyncFn[, error][, message])` 606<!-- YAML 607added: v10.0.0 608--> 609 610* `asyncFn` {Function|Promise} 611* `error` {RegExp|Function} 612* `message` {string} 613 614Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately 615calls the function and awaits the returned promise to complete. It will then 616check that the promise is not rejected. 617 618If `asyncFn` is a function and it throws an error synchronously, 619`assert.doesNotReject()` will return a rejected `Promise` with that error. If 620the function does not return a promise, `assert.doesNotReject()` will return a 621rejected `Promise` with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases 622the error handler is skipped. 623 624Using `assert.doesNotReject()` is actually not useful because there is little 625benefit in catching a rejection and then rejecting it again. Instead, consider 626adding a comment next to the specific code path that should not reject and keep 627error messages as expressive as possible. 628 629If specified, `error` can be a [`Class`][], [`RegExp`][] or a validation 630function. See [`assert.throws()`][] for more details. 631 632Besides the async nature to await the completion behaves identically to 633[`assert.doesNotThrow()`][]. 634 635<!-- eslint-disable no-restricted-syntax --> 636```js 637(async () => { 638 await assert.doesNotReject( 639 async () => { 640 throw new TypeError('Wrong value'); 641 }, 642 SyntaxError 643 ); 644})(); 645``` 646 647<!-- eslint-disable no-restricted-syntax --> 648```js 649assert.doesNotReject(Promise.reject(new TypeError('Wrong value'))) 650 .then(() => { 651 // ... 652 }); 653``` 654 655## `assert.doesNotThrow(fn[, error][, message])` 656<!-- YAML 657added: v0.1.21 658changes: 659 - version: v5.11.0, v4.4.5 660 pr-url: https://github.com/nodejs/node/pull/2407 661 description: The `message` parameter is respected now. 662 - version: v4.2.0 663 pr-url: https://github.com/nodejs/node/pull/3276 664 description: The `error` parameter can now be an arrow function. 665--> 666 667* `fn` {Function} 668* `error` {RegExp|Function} 669* `message` {string} 670 671Asserts that the function `fn` does not throw an error. 672 673Using `assert.doesNotThrow()` is actually not useful because there 674is no benefit in catching an error and then rethrowing it. Instead, consider 675adding a comment next to the specific code path that should not throw and keep 676error messages as expressive as possible. 677 678When `assert.doesNotThrow()` is called, it will immediately call the `fn` 679function. 680 681If an error is thrown and it is the same type as that specified by the `error` 682parameter, then an [`AssertionError`][] is thrown. If the error is of a 683different type, or if the `error` parameter is undefined, the error is 684propagated back to the caller. 685 686If specified, `error` can be a [`Class`][], [`RegExp`][] or a validation 687function. See [`assert.throws()`][] for more details. 688 689The following, for instance, will throw the [`TypeError`][] because there is no 690matching error type in the assertion: 691 692<!-- eslint-disable no-restricted-syntax --> 693```js 694assert.doesNotThrow( 695 () => { 696 throw new TypeError('Wrong value'); 697 }, 698 SyntaxError 699); 700``` 701 702However, the following will result in an [`AssertionError`][] with the message 703'Got unwanted exception...': 704 705<!-- eslint-disable no-restricted-syntax --> 706```js 707assert.doesNotThrow( 708 () => { 709 throw new TypeError('Wrong value'); 710 }, 711 TypeError 712); 713``` 714 715If an [`AssertionError`][] is thrown and a value is provided for the `message` 716parameter, the value of `message` will be appended to the [`AssertionError`][] 717message: 718 719<!-- eslint-disable no-restricted-syntax --> 720```js 721assert.doesNotThrow( 722 () => { 723 throw new TypeError('Wrong value'); 724 }, 725 /Wrong value/, 726 'Whoops' 727); 728// Throws: AssertionError: Got unwanted exception: Whoops 729``` 730 731## `assert.equal(actual, expected[, message])` 732<!-- YAML 733added: v0.1.21 734--> 735 736* `actual` {any} 737* `expected` {any} 738* `message` {string|Error} 739 740**Strict assertion mode** 741 742An alias of [`assert.strictEqual()`][]. 743 744**Legacy assertion mode** 745 746> Stability: 0 - Deprecated: Use [`assert.strictEqual()`][] instead. 747 748Tests shallow, coercive equality between the `actual` and `expected` parameters 749using the [Abstract Equality Comparison][] ( `==` ). 750 751```js 752const assert = require('assert'); 753 754assert.equal(1, 1); 755// OK, 1 == 1 756assert.equal(1, '1'); 757// OK, 1 == '1' 758 759assert.equal(1, 2); 760// AssertionError: 1 == 2 761assert.equal({ a: { b: 1 } }, { a: { b: 1 } }); 762// AssertionError: { a: { b: 1 } } == { a: { b: 1 } } 763``` 764 765If the values are not equal, an [`AssertionError`][] is thrown with a `message` 766property set equal to the value of the `message` parameter. If the `message` 767parameter is undefined, a default error message is assigned. If the `message` 768parameter is an instance of an [`Error`][] then it will be thrown instead of the 769`AssertionError`. 770 771## `assert.fail([message])` 772<!-- YAML 773added: v0.1.21 774--> 775 776* `message` {string|Error} **Default:** `'Failed'` 777 778Throws an [`AssertionError`][] with the provided error message or a default 779error message. If the `message` parameter is an instance of an [`Error`][] then 780it will be thrown instead of the [`AssertionError`][]. 781 782```js 783const assert = require('assert').strict; 784 785assert.fail(); 786// AssertionError [ERR_ASSERTION]: Failed 787 788assert.fail('boom'); 789// AssertionError [ERR_ASSERTION]: boom 790 791assert.fail(new TypeError('need array')); 792// TypeError: need array 793``` 794 795Using `assert.fail()` with more than two arguments is possible but deprecated. 796See below for further details. 797 798## `assert.fail(actual, expected[, message[, operator[, stackStartFn]]])` 799<!-- YAML 800added: v0.1.21 801changes: 802 - version: v10.0.0 803 pr-url: https://github.com/nodejs/node/pull/18418 804 description: Calling `assert.fail()` with more than one argument is 805 deprecated and emits a warning. 806--> 807 808> Stability: 0 - Deprecated: Use `assert.fail([message])` or other assert 809> functions instead. 810 811* `actual` {any} 812* `expected` {any} 813* `message` {string|Error} 814* `operator` {string} **Default:** `'!='` 815* `stackStartFn` {Function} **Default:** `assert.fail` 816 817If `message` is falsy, the error message is set as the values of `actual` and 818`expected` separated by the provided `operator`. If just the two `actual` and 819`expected` arguments are provided, `operator` will default to `'!='`. If 820`message` is provided as third argument it will be used as the error message and 821the other arguments will be stored as properties on the thrown object. If 822`stackStartFn` is provided, all stack frames above that function will be 823removed from stacktrace (see [`Error.captureStackTrace`][]). If no arguments are 824given, the default message `Failed` will be used. 825 826```js 827const assert = require('assert').strict; 828 829assert.fail('a', 'b'); 830// AssertionError [ERR_ASSERTION]: 'a' != 'b' 831 832assert.fail(1, 2, undefined, '>'); 833// AssertionError [ERR_ASSERTION]: 1 > 2 834 835assert.fail(1, 2, 'fail'); 836// AssertionError [ERR_ASSERTION]: fail 837 838assert.fail(1, 2, 'whoops', '>'); 839// AssertionError [ERR_ASSERTION]: whoops 840 841assert.fail(1, 2, new TypeError('need array')); 842// TypeError: need array 843``` 844 845In the last three cases `actual`, `expected`, and `operator` have no 846influence on the error message. 847 848Example use of `stackStartFn` for truncating the exception's stacktrace: 849 850```js 851function suppressFrame() { 852 assert.fail('a', 'b', undefined, '!==', suppressFrame); 853} 854suppressFrame(); 855// AssertionError [ERR_ASSERTION]: 'a' !== 'b' 856// at repl:1:1 857// at ContextifyScript.Script.runInThisContext (vm.js:44:33) 858// ... 859``` 860 861## `assert.ifError(value)` 862<!-- YAML 863added: v0.1.97 864changes: 865 - version: v10.0.0 866 pr-url: https://github.com/nodejs/node/pull/18247 867 description: Instead of throwing the original error it is now wrapped into 868 an [`AssertionError`][] that contains the full stack trace. 869 - version: v10.0.0 870 pr-url: https://github.com/nodejs/node/pull/18247 871 description: Value may now only be `undefined` or `null`. Before all falsy 872 values were handled the same as `null` and did not throw. 873--> 874 875* `value` {any} 876 877Throws `value` if `value` is not `undefined` or `null`. This is useful when 878testing the `error` argument in callbacks. The stack trace contains all frames 879from the error passed to `ifError()` including the potential new frames for 880`ifError()` itself. 881 882```js 883const assert = require('assert').strict; 884 885assert.ifError(null); 886// OK 887assert.ifError(0); 888// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 0 889assert.ifError('error'); 890// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: 'error' 891assert.ifError(new Error()); 892// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: Error 893 894// Create some random error frames. 895let err; 896(function errorFrame() { 897 err = new Error('test error'); 898})(); 899 900(function ifErrorFrame() { 901 assert.ifError(err); 902})(); 903// AssertionError [ERR_ASSERTION]: ifError got unwanted exception: test error 904// at ifErrorFrame 905// at errorFrame 906``` 907 908## `assert.match(string, regexp[, message])` 909<!-- YAML 910added: v12.16.0 911--> 912 913* `string` {string} 914* `regexp` {RegExp} 915* `message` {string|Error} 916 917> Stability: 1 - Experimental 918 919Expects the `string` input to match the regular expression. 920 921This feature is currently experimental and the name might change or it might be 922completely removed again. 923 924```js 925const assert = require('assert').strict; 926 927assert.match('I will fail', /pass/); 928// AssertionError [ERR_ASSERTION]: The input did not match the regular ... 929 930assert.match(123, /pass/); 931// AssertionError [ERR_ASSERTION]: The "string" argument must be of type string. 932 933assert.match('I will pass', /pass/); 934// OK 935``` 936 937If the values do not match, or if the `string` argument is of another type than 938`string`, an [`AssertionError`][] is thrown with a `message` property set equal 939to the value of the `message` parameter. If the `message` parameter is 940undefined, a default error message is assigned. If the `message` parameter is an 941instance of an [`Error`][] then it will be thrown instead of the 942[`AssertionError`][]. 943 944## `assert.notDeepEqual(actual, expected[, message])` 945<!-- YAML 946added: v0.1.21 947changes: 948 - version: v9.0.0 949 pr-url: https://github.com/nodejs/node/pull/15001 950 description: The `Error` names and messages are now properly compared 951 - version: v8.0.0 952 pr-url: https://github.com/nodejs/node/pull/12142 953 description: The `Set` and `Map` content is also compared 954 - version: v6.4.0, v4.7.1 955 pr-url: https://github.com/nodejs/node/pull/8002 956 description: Typed array slices are handled correctly now. 957 - version: v6.1.0, v4.5.0 958 pr-url: https://github.com/nodejs/node/pull/6432 959 description: Objects with circular references can be used as inputs now. 960 - version: v5.10.1, v4.4.3 961 pr-url: https://github.com/nodejs/node/pull/5910 962 description: Handle non-`Uint8Array` typed arrays correctly. 963--> 964 965* `actual` {any} 966* `expected` {any} 967* `message` {string|Error} 968 969**Strict assertion mode** 970 971An alias of [`assert.notDeepStrictEqual()`][]. 972 973**Legacy assertion mode** 974 975> Stability: 0 - Deprecated: Use [`assert.notDeepStrictEqual()`][] instead. 976 977Tests for any deep inequality. Opposite of [`assert.deepEqual()`][]. 978 979```js 980const assert = require('assert'); 981 982const obj1 = { 983 a: { 984 b: 1 985 } 986}; 987const obj2 = { 988 a: { 989 b: 2 990 } 991}; 992const obj3 = { 993 a: { 994 b: 1 995 } 996}; 997const obj4 = Object.create(obj1); 998 999assert.notDeepEqual(obj1, obj1); 1000// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } 1001 1002assert.notDeepEqual(obj1, obj2); 1003// OK 1004 1005assert.notDeepEqual(obj1, obj3); 1006// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } } 1007 1008assert.notDeepEqual(obj1, obj4); 1009// OK 1010``` 1011 1012If the values are deeply equal, an [`AssertionError`][] is thrown with a 1013`message` property set equal to the value of the `message` parameter. If the 1014`message` parameter is undefined, a default error message is assigned. If the 1015`message` parameter is an instance of an [`Error`][] then it will be thrown 1016instead of the `AssertionError`. 1017 1018## `assert.notDeepStrictEqual(actual, expected[, message])` 1019<!-- YAML 1020added: v1.2.0 1021changes: 1022 - version: v9.0.0 1023 pr-url: https://github.com/nodejs/node/pull/15398 1024 description: The `-0` and `+0` are not considered equal anymore. 1025 - version: v9.0.0 1026 pr-url: https://github.com/nodejs/node/pull/15036 1027 description: The `NaN` is now compared using the 1028 [SameValueZero](https://tc39.github.io/ecma262/#sec-samevaluezero) 1029 comparison. 1030 - version: v9.0.0 1031 pr-url: https://github.com/nodejs/node/pull/15001 1032 description: The `Error` names and messages are now properly compared 1033 - version: v8.0.0 1034 pr-url: https://github.com/nodejs/node/pull/12142 1035 description: The `Set` and `Map` content is also compared 1036 - version: v6.4.0, v4.7.1 1037 pr-url: https://github.com/nodejs/node/pull/8002 1038 description: Typed array slices are handled correctly now. 1039 - version: v6.1.0 1040 pr-url: https://github.com/nodejs/node/pull/6432 1041 description: Objects with circular references can be used as inputs now. 1042 - version: v5.10.1, v4.4.3 1043 pr-url: https://github.com/nodejs/node/pull/5910 1044 description: Handle non-`Uint8Array` typed arrays correctly. 1045--> 1046 1047* `actual` {any} 1048* `expected` {any} 1049* `message` {string|Error} 1050 1051Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][]. 1052 1053```js 1054const assert = require('assert').strict; 1055 1056assert.notDeepStrictEqual({ a: 1 }, { a: '1' }); 1057// OK 1058``` 1059 1060If the values are deeply and strictly equal, an [`AssertionError`][] is thrown 1061with a `message` property set equal to the value of the `message` parameter. If 1062the `message` parameter is undefined, a default error message is assigned. If 1063the `message` parameter is an instance of an [`Error`][] then it will be thrown 1064instead of the [`AssertionError`][]. 1065 1066## `assert.notEqual(actual, expected[, message])` 1067<!-- YAML 1068added: v0.1.21 1069--> 1070 1071* `actual` {any} 1072* `expected` {any} 1073* `message` {string|Error} 1074 1075**Strict assertion mode** 1076 1077An alias of [`assert.notStrictEqual()`][]. 1078 1079**Legacy assertion mode** 1080 1081> Stability: 0 - Deprecated: Use [`assert.notStrictEqual()`][] instead. 1082 1083Tests shallow, coercive inequality with the [Abstract Equality Comparison][] 1084( `!=` ). 1085 1086```js 1087const assert = require('assert'); 1088 1089assert.notEqual(1, 2); 1090// OK 1091 1092assert.notEqual(1, 1); 1093// AssertionError: 1 != 1 1094 1095assert.notEqual(1, '1'); 1096// AssertionError: 1 != '1' 1097``` 1098 1099If the values are equal, an [`AssertionError`][] is thrown with a `message` 1100property set equal to the value of the `message` parameter. If the `message` 1101parameter is undefined, a default error message is assigned. If the `message` 1102parameter is an instance of an [`Error`][] then it will be thrown instead of the 1103`AssertionError`. 1104 1105## `assert.notStrictEqual(actual, expected[, message])` 1106<!-- YAML 1107added: v0.1.21 1108changes: 1109 - version: v10.0.0 1110 pr-url: https://github.com/nodejs/node/pull/17003 1111 description: Used comparison changed from Strict Equality to `Object.is()` 1112--> 1113 1114* `actual` {any} 1115* `expected` {any} 1116* `message` {string|Error} 1117 1118Tests strict inequality between the `actual` and `expected` parameters as 1119determined by the [SameValue Comparison][]. 1120 1121```js 1122const assert = require('assert').strict; 1123 1124assert.notStrictEqual(1, 2); 1125// OK 1126 1127assert.notStrictEqual(1, 1); 1128// AssertionError [ERR_ASSERTION]: Expected "actual" to be strictly unequal to: 1129// 1130// 1 1131 1132assert.notStrictEqual(1, '1'); 1133// OK 1134``` 1135 1136If the values are strictly equal, an [`AssertionError`][] is thrown with a 1137`message` property set equal to the value of the `message` parameter. If the 1138`message` parameter is undefined, a default error message is assigned. If the 1139`message` parameter is an instance of an [`Error`][] then it will be thrown 1140instead of the `AssertionError`. 1141 1142## `assert.ok(value[, message])` 1143<!-- YAML 1144added: v0.1.21 1145changes: 1146 - version: v10.0.0 1147 pr-url: https://github.com/nodejs/node/pull/18319 1148 description: The `assert.ok()` (no arguments) will now use a predefined 1149 error message. 1150--> 1151 1152* `value` {any} 1153* `message` {string|Error} 1154 1155Tests if `value` is truthy. It is equivalent to 1156`assert.equal(!!value, true, message)`. 1157 1158If `value` is not truthy, an [`AssertionError`][] is thrown with a `message` 1159property set equal to the value of the `message` parameter. If the `message` 1160parameter is `undefined`, a default error message is assigned. If the `message` 1161parameter is an instance of an [`Error`][] then it will be thrown instead of the 1162`AssertionError`. 1163If no arguments are passed in at all `message` will be set to the string: 1164``'No value argument passed to `assert.ok()`'``. 1165 1166Be aware that in the `repl` the error message will be different to the one 1167thrown in a file! See below for further details. 1168 1169```js 1170const assert = require('assert').strict; 1171 1172assert.ok(true); 1173// OK 1174assert.ok(1); 1175// OK 1176 1177assert.ok(); 1178// AssertionError: No value argument passed to `assert.ok()` 1179 1180assert.ok(false, 'it\'s false'); 1181// AssertionError: it's false 1182 1183// In the repl: 1184assert.ok(typeof 123 === 'string'); 1185// AssertionError: false == true 1186 1187// In a file (e.g. test.js): 1188assert.ok(typeof 123 === 'string'); 1189// AssertionError: The expression evaluated to a falsy value: 1190// 1191// assert.ok(typeof 123 === 'string') 1192 1193assert.ok(false); 1194// AssertionError: The expression evaluated to a falsy value: 1195// 1196// assert.ok(false) 1197 1198assert.ok(0); 1199// AssertionError: The expression evaluated to a falsy value: 1200// 1201// assert.ok(0) 1202 1203// Using `assert()` works the same: 1204assert(0); 1205// AssertionError: The expression evaluated to a falsy value: 1206// 1207// assert(0) 1208``` 1209 1210## `assert.rejects(asyncFn[, error][, message])` 1211<!-- YAML 1212added: v10.0.0 1213--> 1214 1215* `asyncFn` {Function|Promise} 1216* `error` {RegExp|Function|Object|Error} 1217* `message` {string} 1218 1219Awaits the `asyncFn` promise or, if `asyncFn` is a function, immediately 1220calls the function and awaits the returned promise to complete. It will then 1221check that the promise is rejected. 1222 1223If `asyncFn` is a function and it throws an error synchronously, 1224`assert.rejects()` will return a rejected `Promise` with that error. If the 1225function does not return a promise, `assert.rejects()` will return a rejected 1226`Promise` with an [`ERR_INVALID_RETURN_VALUE`][] error. In both cases the error 1227handler is skipped. 1228 1229Besides the async nature to await the completion behaves identically to 1230[`assert.throws()`][]. 1231 1232If specified, `error` can be a [`Class`][], [`RegExp`][], a validation function, 1233an object where each property will be tested for, or an instance of error where 1234each property will be tested for including the non-enumerable `message` and 1235`name` properties. 1236 1237If specified, `message` will be the message provided by the [`AssertionError`][] 1238if the `asyncFn` fails to reject. 1239 1240```js 1241(async () => { 1242 await assert.rejects( 1243 async () => { 1244 throw new TypeError('Wrong value'); 1245 }, 1246 { 1247 name: 'TypeError', 1248 message: 'Wrong value' 1249 } 1250 ); 1251})(); 1252``` 1253 1254```js 1255(async () => { 1256 await assert.rejects( 1257 async () => { 1258 throw new TypeError('Wrong value'); 1259 }, 1260 (err) => { 1261 assert.strictEqual(err.name, 'TypeError'); 1262 assert.strictEqual(err.message, 'Wrong value'); 1263 return true; 1264 } 1265 ); 1266})(); 1267``` 1268 1269```js 1270assert.rejects( 1271 Promise.reject(new Error('Wrong value')), 1272 Error 1273).then(() => { 1274 // ... 1275}); 1276``` 1277 1278`error` cannot be a string. If a string is provided as the second 1279argument, then `error` is assumed to be omitted and the string will be used for 1280`message` instead. This can lead to easy-to-miss mistakes. Please read the 1281example in [`assert.throws()`][] carefully if using a string as the second 1282argument gets considered. 1283 1284## `assert.strictEqual(actual, expected[, message])` 1285<!-- YAML 1286added: v0.1.21 1287changes: 1288 - version: v10.0.0 1289 pr-url: https://github.com/nodejs/node/pull/17003 1290 description: Used comparison changed from Strict Equality to `Object.is()` 1291--> 1292 1293* `actual` {any} 1294* `expected` {any} 1295* `message` {string|Error} 1296 1297Tests strict equality between the `actual` and `expected` parameters as 1298determined by the [SameValue Comparison][]. 1299 1300```js 1301const assert = require('assert').strict; 1302 1303assert.strictEqual(1, 2); 1304// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal: 1305// 1306// 1 !== 2 1307 1308assert.strictEqual(1, 1); 1309// OK 1310 1311assert.strictEqual('Hello foobar', 'Hello World!'); 1312// AssertionError [ERR_ASSERTION]: Expected inputs to be strictly equal: 1313// + actual - expected 1314// 1315// + 'Hello foobar' 1316// - 'Hello World!' 1317// ^ 1318 1319const apples = 1; 1320const oranges = 2; 1321assert.strictEqual(apples, oranges, `apples ${apples} !== oranges ${oranges}`); 1322// AssertionError [ERR_ASSERTION]: apples 1 !== oranges 2 1323 1324assert.strictEqual(1, '1', new TypeError('Inputs are not identical')); 1325// TypeError: Inputs are not identical 1326``` 1327 1328If the values are not strictly equal, an [`AssertionError`][] is thrown with a 1329`message` property set equal to the value of the `message` parameter. If the 1330`message` parameter is undefined, a default error message is assigned. If the 1331`message` parameter is an instance of an [`Error`][] then it will be thrown 1332instead of the [`AssertionError`][]. 1333 1334## `assert.throws(fn[, error][, message])` 1335<!-- YAML 1336added: v0.1.21 1337changes: 1338 - version: v10.2.0 1339 pr-url: https://github.com/nodejs/node/pull/20485 1340 description: The `error` parameter can be an object containing regular 1341 expressions now. 1342 - version: v9.9.0 1343 pr-url: https://github.com/nodejs/node/pull/17584 1344 description: The `error` parameter can now be an object as well. 1345 - version: v4.2.0 1346 pr-url: https://github.com/nodejs/node/pull/3276 1347 description: The `error` parameter can now be an arrow function. 1348--> 1349 1350* `fn` {Function} 1351* `error` {RegExp|Function|Object|Error} 1352* `message` {string} 1353 1354Expects the function `fn` to throw an error. 1355 1356If specified, `error` can be a [`Class`][], [`RegExp`][], a validation function, 1357a validation object where each property will be tested for strict deep equality, 1358or an instance of error where each property will be tested for strict deep 1359equality including the non-enumerable `message` and `name` properties. When 1360using an object, it is also possible to use a regular expression, when 1361validating against a string property. See below for examples. 1362 1363If specified, `message` will be appended to the message provided by the 1364`AssertionError` if the `fn` call fails to throw or in case the error validation 1365fails. 1366 1367Custom validation object/error instance: 1368 1369```js 1370const err = new TypeError('Wrong value'); 1371err.code = 404; 1372err.foo = 'bar'; 1373err.info = { 1374 nested: true, 1375 baz: 'text' 1376}; 1377err.reg = /abc/i; 1378 1379assert.throws( 1380 () => { 1381 throw err; 1382 }, 1383 { 1384 name: 'TypeError', 1385 message: 'Wrong value', 1386 info: { 1387 nested: true, 1388 baz: 'text' 1389 } 1390 // Only properties on the validation object will be tested for. 1391 // Using nested objects requires all properties to be present. Otherwise 1392 // the validation is going to fail. 1393 } 1394); 1395 1396// Using regular expressions to validate error properties: 1397assert.throws( 1398 () => { 1399 throw err; 1400 }, 1401 { 1402 // The `name` and `message` properties are strings and using regular 1403 // expressions on those will match against the string. If they fail, an 1404 // error is thrown. 1405 name: /^TypeError$/, 1406 message: /Wrong/, 1407 foo: 'bar', 1408 info: { 1409 nested: true, 1410 // It is not possible to use regular expressions for nested properties! 1411 baz: 'text' 1412 }, 1413 // The `reg` property contains a regular expression and only if the 1414 // validation object contains an identical regular expression, it is going 1415 // to pass. 1416 reg: /abc/i 1417 } 1418); 1419 1420// Fails due to the different `message` and `name` properties: 1421assert.throws( 1422 () => { 1423 const otherErr = new Error('Not found'); 1424 // Copy all enumerable properties from `err` to `otherErr`. 1425 for (const [key, value] of Object.entries(err)) { 1426 otherErr[key] = value; 1427 } 1428 throw otherErr; 1429 }, 1430 // The error's `message` and `name` properties will also be checked when using 1431 // an error as validation object. 1432 err 1433); 1434``` 1435 1436Validate instanceof using constructor: 1437 1438```js 1439assert.throws( 1440 () => { 1441 throw new Error('Wrong value'); 1442 }, 1443 Error 1444); 1445``` 1446 1447Validate error message using [`RegExp`][]: 1448 1449Using a regular expression runs `.toString` on the error object, and will 1450therefore also include the error name. 1451 1452```js 1453assert.throws( 1454 () => { 1455 throw new Error('Wrong value'); 1456 }, 1457 /^Error: Wrong value$/ 1458); 1459``` 1460 1461Custom error validation: 1462 1463The function must return `true` to indicate all internal validations passed. 1464It will otherwise fail with an [`AssertionError`][]. 1465 1466```js 1467assert.throws( 1468 () => { 1469 throw new Error('Wrong value'); 1470 }, 1471 (err) => { 1472 assert(err instanceof Error); 1473 assert(/value/.test(err)); 1474 // Avoid returning anything from validation functions besides `true`. 1475 // Otherwise, it's not clear what part of the validation failed. Instead, 1476 // throw an error about the specific validation that failed (as done in this 1477 // example) and add as much helpful debugging information to that error as 1478 // possible. 1479 return true; 1480 }, 1481 'unexpected error' 1482); 1483``` 1484 1485`error` cannot be a string. If a string is provided as the second 1486argument, then `error` is assumed to be omitted and the string will be used for 1487`message` instead. This can lead to easy-to-miss mistakes. Using the same 1488message as the thrown error message is going to result in an 1489`ERR_AMBIGUOUS_ARGUMENT` error. Please read the example below carefully if using 1490a string as the second argument gets considered: 1491 1492<!-- eslint-disable no-restricted-syntax --> 1493```js 1494function throwingFirst() { 1495 throw new Error('First'); 1496} 1497 1498function throwingSecond() { 1499 throw new Error('Second'); 1500} 1501 1502function notThrowing() {} 1503 1504// The second argument is a string and the input function threw an Error. 1505// The first case will not throw as it does not match for the error message 1506// thrown by the input function! 1507assert.throws(throwingFirst, 'Second'); 1508// In the next example the message has no benefit over the message from the 1509// error and since it is not clear if the user intended to actually match 1510// against the error message, Node.js throws an `ERR_AMBIGUOUS_ARGUMENT` error. 1511assert.throws(throwingSecond, 'Second'); 1512// TypeError [ERR_AMBIGUOUS_ARGUMENT] 1513 1514// The string is only used (as message) in case the function does not throw: 1515assert.throws(notThrowing, 'Second'); 1516// AssertionError [ERR_ASSERTION]: Missing expected exception: Second 1517 1518// If it was intended to match for the error message do this instead: 1519// It does not throw because the error messages match. 1520assert.throws(throwingSecond, /Second$/); 1521 1522// If the error message does not match, an AssertionError is thrown. 1523assert.throws(throwingFirst, /Second$/); 1524// AssertionError [ERR_ASSERTION] 1525``` 1526 1527Due to the confusing error-prone notation, avoid a string as the second 1528argument. 1529 1530[`AssertionError`]: #assert_class_assert_assertionerror 1531[`Class`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes 1532[`ERR_INVALID_RETURN_VALUE`]: errors.html#errors_err_invalid_return_value 1533[`Error.captureStackTrace`]: errors.html#errors_error_capturestacktrace_targetobject_constructoropt 1534[`Error`]: errors.html#errors_class_error 1535[`Map`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map 1536[`Object.is()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is 1537[`RegExp`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 1538[`Set`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set 1539[`Symbol`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol 1540[`TypeError`]: errors.html#errors_class_typeerror 1541[`WeakMap`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap 1542[`WeakSet`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakSet 1543[`CallTracker`]: #assert_class_assert_calltracker 1544[`assert.deepEqual()`]: #assert_assert_deepequal_actual_expected_message 1545[`assert.deepStrictEqual()`]: #assert_assert_deepstrictequal_actual_expected_message 1546[`assert.doesNotThrow()`]: #assert_assert_doesnotthrow_fn_error_message 1547[`assert.equal()`]: #assert_assert_equal_actual_expected_message 1548[`assert.notDeepEqual()`]: #assert_assert_notdeepequal_actual_expected_message 1549[`assert.notDeepStrictEqual()`]: #assert_assert_notdeepstrictequal_actual_expected_message 1550[`assert.notEqual()`]: #assert_assert_notequal_actual_expected_message 1551[`assert.notStrictEqual()`]: #assert_assert_notstrictequal_actual_expected_message 1552[`assert.ok()`]: #assert_assert_ok_value_message 1553[`assert.strictEqual()`]: #assert_assert_strictequal_actual_expected_message 1554[`assert.throws()`]: #assert_assert_throws_fn_error_message 1555[`process.on('exit')`]: process.html#process_event_exit 1556[`tracker.calls()`]: #assert_tracker_calls_fn_exact 1557[`tracker.verify()`]: #assert_tracker_verify 1558[strict assertion mode]: #assert_strict_assertion_mode 1559[Abstract Equality Comparison]: https://tc39.github.io/ecma262/#sec-abstract-equality-comparison 1560[Object wrappers]: https://developer.mozilla.org/en-US/docs/Glossary/Primitive#Primitive_wrapper_objects_in_JavaScript 1561[Object.prototype.toString()]: https://tc39.github.io/ecma262/#sec-object.prototype.tostring 1562[SameValue Comparison]: https://tc39.github.io/ecma262/#sec-samevalue 1563[Strict Equality Comparison]: https://tc39.github.io/ecma262/#sec-strict-equality-comparison 1564[enumerable "own" properties]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties 1565[prototype-spec]: https://tc39.github.io/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots 1566