summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2018-12-13 07:33:31 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2019-01-27 03:34:25 +0100
commit7493db21b667ed746d39c9b54357eac4287232e3 (patch)
treee6ae60900e43b5fa3d5dcdc8171782ae60192bb1 /doc
parent5cb196441a6df0fc3fa62e042ce108347f49814c (diff)
downloadandroid-node-v8-7493db21b667ed746d39c9b54357eac4287232e3.tar.gz
android-node-v8-7493db21b667ed746d39c9b54357eac4287232e3.tar.bz2
android-node-v8-7493db21b667ed746d39c9b54357eac4287232e3.zip
assert: adjust loose assertions
This changes the loose deep equal comparison by using the same logic as done in the strict deep equal comparison besides comparing primitives loosely, not comparing symbol properties and not comparing the prototype. `assert.deepEqual` is still commenly used and this is likely the biggest pitfall. Most changes are only minor and won't have a big impact besides likely fixing user expectations. PR-URL: https://github.com/nodejs/node/pull/25008 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/assert.md47
1 files changed, 32 insertions, 15 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md
index 4c4b2c4250..67bc9afbab 100644
--- a/doc/api/assert.md
+++ b/doc/api/assert.md
@@ -163,6 +163,10 @@ An alias of [`assert.ok()`][].
<!-- YAML
added: v0.1.21
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/25008
+ description: The type tags are now properly compared and there are a couple
+ minor comparison adjustments to make the check less surprising.
- version: v9.0.0
pr-url: https://github.com/nodejs/node/pull/15001
description: The `Error` names and messages are now properly compared
@@ -191,26 +195,39 @@ An alias of [`assert.deepStrictEqual()`][].
> Stability: 0 - Deprecated: Use [`assert.deepStrictEqual()`][] instead.
-Tests for deep equality between the `actual` and `expected` parameters.
-Primitive values are compared with the [Abstract Equality Comparison][]
-( `==` ).
+Tests for deep equality between the `actual` and `expected` parameters. Consider
+using [`assert.deepStrictEqual()`][] instead. [`assert.deepEqual()`][] can have
+potentially surprising results.
+
+"Deep" equality means that the enumerable "own" properties of child objects
+are also recursively evaluated by the following rules.
+
+### Comparison details
+
+* Primitive values are compared with the [Abstract Equality Comparison][]
+ ( `==` ).
+* [Type tags][Object.prototype.toString()] of objects should be the same.
+* Only [enumerable "own" properties][] are considered.
+* [`Error`][] names and messages are always compared, even if these are not
+ enumerable properties.
+* [Object wrappers][] are compared both as objects and unwrapped values.
+* `Object` properties are compared unordered.
+* [`Map`][] keys and [`Set`][] items are compared unordered.
+* Recursion stops when both sides differ or both sides encounter a circular
+ reference.
+* Implementation does not test the [`[[Prototype]]`][prototype-spec] of
+ objects.
+* [`Symbol`][] properties are not compared.
+* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values.
-Only [enumerable "own" properties][] are considered. The
-[`assert.deepEqual()`][] implementation does not test the
-[`[[Prototype]]`][prototype-spec] of objects or enumerable own [`Symbol`][]
-properties. For such checks, consider using [`assert.deepStrictEqual()`][]
-instead. [`assert.deepEqual()`][] can have potentially surprising results. The
-following example does not throw an `AssertionError` because the properties on
-the [`RegExp`][] object are not enumerable:
+The following example does not throw an `AssertionError` because the primitives
+are considered equal by the [Abstract Equality Comparison][] ( `==` ).
```js
// WARNING: This does not throw an AssertionError!
-assert.deepEqual(/a/gi, new Date());
+assert.deepEqual('+00000000', false);
```
-An exception is made for [`Map`][] and [`Set`][]. `Map`s and `Set`s have their
-contained items compared too, as expected.
-
"Deep" equality means that the enumerable "own" properties of child objects
are evaluated also:
@@ -304,7 +321,7 @@ are recursively evaluated also by the following rules.
* Enumerable own [`Symbol`][] properties are compared as well.
* [Object wrappers][] are compared both as objects and unwrapped values.
* `Object` properties are compared unordered.
-* `Map` keys and `Set` items are compared unordered.
+* [`Map`][] keys and [`Set`][] items are compared unordered.
* Recursion stops when both sides differ or both sides encounter a circular
reference.
* [`WeakMap`][] and [`WeakSet`][] comparison does not rely on their values. See