diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index cf80cf598d6938..2959f54c7a1c4a 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -44,6 +44,19 @@ assert.ok(a.AssertionError.prototype instanceof Error, assert.throws(() => a(false), a.AssertionError, 'ok(false)'); assert.throws(() => a.ok(false), a.AssertionError, 'ok(false)'); +// Throw message if the message is instanceof Error. +{ + let threw = false; + try { + assert.ok(false, new Error('ok(false)')); + } catch (e) { + threw = true; + assert.ok(e instanceof Error); + } + assert.ok(threw, 'Error: ok(false)'); +} + + a(true); a('test', 'ok(\'test\')'); a.ok(true); @@ -165,6 +178,17 @@ assert.throws( } ); +assert.throws( + () => a.doesNotThrow(() => thrower(Error), /\[[a-z]{6}\s[A-z]{6}\]/g, 'user message'), + { + name: 'AssertionError', + code: 'ERR_ASSERTION', + operator: 'doesNotThrow', + message: 'Got unwanted exception: user message\n' + + 'Actual message: "[object Object]"' + } +); + // Make sure that validating using constructor really works. { let threw = false;