Skip to content

Commit

Permalink
doc: update assert documentation
Browse files Browse the repository at this point in the history
This adds concrete expected types to the assert documentation.

It also fixes a `changes` entry and improves some minor comments.

PR-URL: #20486
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
  • Loading branch information
BridgeAR authored and targos committed May 12, 2018
1 parent a5ee31b commit 01abed1
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions doc/api/assert.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ assert.deepEqual(/a/gi, new Date());
<!-- YAML
added: v0.5.9
-->
* `value` {any}
* `message` {any}
* `value` {any} The input that is checked for being truthy.
* `message` {string|Error}

An alias of [`assert.ok()`][].

Expand All @@ -181,7 +181,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

**Strict mode**

Expand Down Expand Up @@ -235,18 +235,18 @@ const obj3 = {
const obj4 = Object.create(obj1);

assert.deepEqual(obj1, obj1);
// OK, object is equal to itself
// OK

// Values of b are different:
assert.deepEqual(obj1, obj2);
// AssertionError: { a: { b: 1 } } deepEqual { a: { b: 2 } }
// values of b are different

assert.deepEqual(obj1, obj3);
// OK, objects are equal
// OK

// Prototypes are ignored:
assert.deepEqual(obj1, obj4);
// AssertionError: { a: { b: 1 } } deepEqual {}
// Prototypes are ignored
```

If the values are not equal, an `AssertionError` is thrown with a `message`
Expand Down Expand Up @@ -285,7 +285,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

Tests for deep equality between the `actual` and `expected` parameters.
"Deep" equality means that the enumerable "own" properties of child objects
Expand Down Expand Up @@ -406,7 +406,7 @@ added: v10.0.0
-->
* `block` {Function|Promise}
* `error` {RegExp|Function}
* `message` {any}
* `message` {string|Error}

Awaits the `block` promise or, if `block` is a function, immediately calls the
function and awaits the returned promise to complete. It will then check that
Expand Down Expand Up @@ -460,7 +460,7 @@ changes:
-->
* `block` {Function}
* `error` {RegExp|Function}
* `message` {any}
* `message` {string|Error}

Asserts that the function `block` does not throw an error.

Expand Down Expand Up @@ -528,7 +528,7 @@ added: v0.1.21
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

**Strict mode**

Expand Down Expand Up @@ -565,7 +565,7 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the
<!-- YAML
added: v0.1.21
-->
* `message` {any} **Default:** `'Failed'`
* `message` {string|Error} **Default:** `'Failed'`

Throws an `AssertionError` with the provided error message or a default error
message. If the `message` parameter is an instance of an [`Error`][] then it
Expand Down Expand Up @@ -598,7 +598,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}
* `operator` {string} **Default:** `'!='`
* `stackStartFunction` {Function} **Default:** `assert.fail`

Expand Down Expand Up @@ -659,8 +659,8 @@ changes:
an `AssertionError` that contains the full stack trace.
- version: v10.0.0
pr-url: https://github.com/nodejs/node/pull/18247
description: Value may now only be `undefined` or `null`. Before any truthy
input was accepted.
description: Value may now only be `undefined` or `null`. Before all falsy
values were handled the same as `null` and did not throw.
-->
* `value` {any}

Expand Down Expand Up @@ -717,7 +717,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

**Strict mode**

Expand Down Expand Up @@ -753,13 +753,13 @@ assert.notDeepEqual(obj1, obj1);
// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }

assert.notDeepEqual(obj1, obj2);
// OK: obj1 and obj2 are not deeply equal
// OK

assert.notDeepEqual(obj1, obj3);
// AssertionError: { a: { b: 1 } } notDeepEqual { a: { b: 1 } }

assert.notDeepEqual(obj1, obj4);
// OK: obj1 and obj4 are not deeply equal
// OK
```

If the values are deeply equal, an `AssertionError` is thrown with a `message`
Expand Down Expand Up @@ -798,7 +798,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

Tests for deep strict inequality. Opposite of [`assert.deepStrictEqual()`][].

Expand All @@ -821,7 +821,7 @@ added: v0.1.21
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

**Strict mode**

Expand Down Expand Up @@ -863,7 +863,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

Tests strict inequality between the `actual` and `expected` parameters as
determined by the [SameValue Comparison][].
Expand Down Expand Up @@ -897,7 +897,7 @@ changes:
error message.
-->
* `value` {any}
* `message` {any}
* `message` {string|Error}

Tests if `value` is truthy. It is equivalent to
`assert.equal(!!value, true, message)`.
Expand Down Expand Up @@ -960,7 +960,7 @@ added: v10.0.0
-->
* `block` {Function|Promise}
* `error` {RegExp|Function|Object|Error}
* `message` {any}
* `message` {string|Error}

Awaits the `block` promise or, if `block` is a function, immediately calls the
function and awaits the returned promise to complete. It will then check that
Expand Down Expand Up @@ -1022,7 +1022,7 @@ changes:
-->
* `actual` {any}
* `expected` {any}
* `message` {any}
* `message` {string|Error}

Tests strict equality between the `actual` and `expected` parameters as
determined by the [SameValue Comparison][].
Expand Down Expand Up @@ -1065,7 +1065,7 @@ changes:
-->
* `block` {Function}
* `error` {RegExp|Function|Object|Error}
* `message` {any}
* `message` {string|Error}

Expects the function `block` to throw an error.

Expand Down

0 comments on commit 01abed1

Please sign in to comment.