Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assert: move assertion part in extra file #20486

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 6 additions & 9 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,12 @@ const {
isDeepEqual,
isDeepStrictEqual
} = require('internal/util/comparisons');
const {
AssertionError,
errorCache,
codes: {
ERR_AMBIGUOUS_ARGUMENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_RETURN_VALUE
}
} = require('internal/errors');
const { codes: {
ERR_AMBIGUOUS_ARGUMENT,
ERR_INVALID_ARG_TYPE,
ERR_INVALID_RETURN_VALUE
} } = require('internal/errors');
const { AssertionError, errorCache } = require('internal/assert');
const { openSync, closeSync, readSync } = require('fs');
const { inspect, types: { isPromise } } = require('util');
const { EOL } = require('os');
Expand Down
Loading