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])