summaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-09 22:54:44 -0200
committerRuben Bridgewater <ruben@bridgewater.de>2017-12-21 03:01:02 -0300
commit2d374916ebbaaa83aaf68577b75d41c6bb6ca9b8 (patch)
tree555da27e4830101e531f48b44220d05e99c2eaa1 /doc
parentfc61ee32fedd5d0bd9bc1dee2b87a41dd7ffa4dd (diff)
downloadandroid-node-v8-2d374916ebbaaa83aaf68577b75d41c6bb6ca9b8.tar.gz
android-node-v8-2d374916ebbaaa83aaf68577b75d41c6bb6ca9b8.tar.bz2
android-node-v8-2d374916ebbaaa83aaf68577b75d41c6bb6ca9b8.zip
assert: .throws accept objects
From now on it is possible to use a validation object in throws instead of the other possibilites. PR-URL: https://github.com/nodejs/node/pull/17584 Refs: https://github.com/nodejs/node/pull/17557 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ron Korving <ron@ronkorving.nl> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Diffstat (limited to 'doc')
-rw-r--r--doc/api/assert.md26
1 files changed, 23 insertions, 3 deletions
diff --git a/doc/api/assert.md b/doc/api/assert.md
index 43c7e8e2d4..75477516bf 100644
--- a/doc/api/assert.md
+++ b/doc/api/assert.md
@@ -711,18 +711,21 @@ instead of the `AssertionError`.
<!-- YAML
added: v0.1.21
changes:
+ - version: REPLACEME
+ pr-url: https://github.com/nodejs/node/pull/REPLACEME
+ description: The `error` parameter can now be an object as well.
- version: v4.2.0
pr-url: https://github.com/nodejs/node/pull/3276
description: The `error` parameter can now be an arrow function.
-->
* `block` {Function}
-* `error` {RegExp|Function}
+* `error` {RegExp|Function|object}
* `message` {any}
Expects the function `block` to throw an error.
-If specified, `error` can be a constructor, [`RegExp`][], or validation
-function.
+If specified, `error` can be a constructor, [`RegExp`][], a validation
+function, or an object where each property will be tested for.
If specified, `message` will be the message provided by the `AssertionError` if
the block fails to throw.
@@ -768,6 +771,23 @@ assert.throws(
);
```
+Custom error object / error instance:
+
+```js
+assert.throws(
+ () => {
+ const err = new TypeError('Wrong value');
+ err.code = 404;
+ throw err;
+ },
+ {
+ name: 'TypeError',
+ message: 'Wrong value'
+ // Note that only properties on the error object will be tested!
+ }
+);
+```
+
Note that `error` can not be a string. If a string is provided as the second
argument, then `error` is assumed to be omitted and the string will be used for
`message` instead. This can lead to easy-to-miss mistakes. Please read the