From e13d1df89bbaf26601b6c1c8406113b80bb6a95c Mon Sep 17 00:00:00 2001 From: geek Date: Sat, 9 Sep 2017 20:36:47 -0500 Subject: [PATCH] assert: support custom errors This commit adds special handling of Error instances when passed as the message argument to assert functions. With this commit, if an Error is passed as the message, then that Error is thrown instead of an AssertionError. PR-URL: https://github.com/nodejs/node/pull/15304 Reviewed-By: Colin Ihrig Reviewed-By: Ruben Bridgewater --- doc/api/assert.md | 59 +++++++++++++++++++++---------- lib/assert.js | 2 ++ test/parallel/test-assert-fail.js | 22 ++++++++++++ test/parallel/test-assert.js | 28 +++++++++++++++ 4 files changed, 93 insertions(+), 18 deletions(-) diff --git a/doc/api/assert.md b/doc/api/assert.md index 504830826b7da4..fd8973efb9ac2d 100644 --- a/doc/api/assert.md +++ b/doc/api/assert.md @@ -101,7 +101,9 @@ assert.deepEqual(obj1, obj4); If the values are not equal, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` -parameter is undefined, a default error message is assigned. +parameter is undefined, a default error message is assigned. If the `message` +parameter is an instance of an `Error` then it will be thrown instead of the +`AssertionError`. ## assert.deepStrictEqual(actual, expected[, message])