From 567284f0c33b725e67ffd2d858a0936a18b71031 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 10 Feb 2017 11:29:42 -0800 Subject: [PATCH] squash: improvements --- lib/assert.js | 4 ++-- test/parallel/test-assert.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 86fd943169c237..4629c883e00091 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -341,8 +341,8 @@ function _throws(shouldThrow, block, expected, message) { actual = _tryBlock(block); - message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + - (message ? ' ' + message : ''); + message = (expected && expected.name ? ' (' + expected.name + ')' : '') + + (message ? ': ' + message : '.'); if (shouldThrow && !actual) { fail(actual, expected, 'Missing expected exception' + message); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 4cb0a52dd85903..bbe8a4db66decf 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -489,6 +489,29 @@ a.throws(makeBlock(a.deepEqual, args, [])); a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs)); } +// check messages from assert.throws() +{ + assert.throws( + () => { a.throws(() => {}); }, + /^AssertionError: Missing expected exception\.$/ + ); + + assert.throws( + () => { a.throws(() => {}, TypeError); }, + /^AssertionError: Missing expected exception \(TypeError\)\.$/ + ); + + assert.throws( + () => { a.throws(() => {}, 'fhqwhgads'); }, + /^AssertionError: Missing expected exception: fhqwhgads$/ + ); + + assert.throws( + () => { a.throws(() => {}, TypeError, 'fhqwhgads'); }, + /^AssertionError: Missing expected exception \(TypeError\): fhqwhgads$/ + ); +} + const circular = {y: 1}; circular.x = circular;