From 5bd5b0b194f86f0361f2dada17028efb999a5baf Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Sun, 2 Jun 2019 01:43:45 +0200 Subject: [PATCH] assert: make deepEqual() closer to deepStrictEqual() deepEqual() and notDeepEqual() are identical to deepStrictEqual() and notDeepStrictEqual() respectively with the exception that prototype/class is not checked. --- doc/api/assert.md | 165 +++--------------- lib/internal/assert/assertion_error.js | 45 ++--- lib/internal/util/comparisons.js | 159 +++-------------- test/parallel/test-assert-deep.js | 121 ++++++------- .../test-assert-typedarray-deepequal.js | 9 - .../test-vm-global-property-interceptors.js | 5 +- 6 files changed, 120 insertions(+), 384 deletions(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index fb33994df1586d..63365762aa8a0b 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -8,6 +8,9 @@ The `assert` module provides a set of assertion functions for verifying invariants. The module provides a recommended [`strict` mode][] and a more lenient legacy mode. +To deactivate colors in output, use the `NODE_DISABLE_COLORS` environment +variable. This will also deactivate the colors in the REPL. + ## Class: assert.AssertionError A subclass of `Error` that indicates the failure of an assertion. All errors @@ -78,8 +81,8 @@ changes: --> In `strict` mode, `assert` functions use the comparison in the corresponding -strict functions. For example, [`assert.deepEqual()`][] will behave like -[`assert.deepStrictEqual()`][]. +strict functions. For example, [`assert.equal()`][] will behave like +[`assert.strictEqual()`][]. In `strict` mode, error messages for objects display a diff. In legacy mode, error messages for objects display the objects, often truncated. @@ -111,17 +114,15 @@ assert.deepEqual([[[1, 2, 3]], 4, 5], [[[1, 2, '3']], 4, 5]); // ] ``` -To deactivate the colors, use the `NODE_DISABLE_COLORS` environment variable. -This will also deactivate the colors in the REPL. - ## Legacy mode -Legacy mode uses the [Abstract Equality Comparison][] in: +When accessing `assert` directly instead of using the `strict` property, the +[Abstract Equality Comparison][] will be used for [`assert.equal()`][] and +[`assert.notEqual()`][]. -* [`assert.deepEqual()`][] -* [`assert.equal()`][] -* [`assert.notDeepEqual()`][] -* [`assert.notEqual()`][] +In legacy mode, [`assert.deepEqual()`][] and [`assert.notDeepEqual()`][] work +the same as in `strict` mode except that the prototypes of the objects are not +compared. To use legacy mode: @@ -130,14 +131,7 @@ const assert = require('assert'); ``` Whenever possible, use the [`strict` mode][] instead. Otherwise, the -[Abstract Equality Comparison][] may cause surprising results. This is -especially true for [`assert.deepEqual()`][], where the comparison rules are -lax: - -```js -// WARNING: This does not throw an AssertionError! -assert.deepEqual(/a/gi, new Date()); -``` +[Abstract Equality Comparison][] may cause surprising results. ## assert(value[, message])