From dab17e80e587299efebfbf2f97fc2b38b00bad62 Mon Sep 17 00:00:00 2001 From: Ruben Bridgewater Date: Wed, 11 Apr 2018 03:28:35 +0200 Subject: [PATCH] assert: fix actual & expected input This makes sure the actual and expected values on the error thrown by `assert.throws` etc. are always as they should be. --- lib/assert.js | 6 +++--- test/parallel/test-assert.js | 34 +++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/lib/assert.js b/lib/assert.js index 5e69e17515dfbc..8edace327a75ee 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -471,7 +471,7 @@ function expectsError(stackStartFn, actual, error, message) { error); } message = error; - error = null; + error = undefined; } if (actual === NO_EXCEPTION_SENTINEL) { @@ -482,7 +482,7 @@ function expectsError(stackStartFn, actual, error, message) { details += message ? `: ${message}` : '.'; const fnType = stackStartFn === rejects ? 'rejection' : 'exception'; innerFail({ - actual, + actual: undefined, expected: error, operator: stackStartFn.name, message: `Missing expected ${fnType}${details}`, @@ -500,7 +500,7 @@ function expectsNoError(stackStartFn, actual, error, message) { if (typeof error === 'string') { message = error; - error = null; + error = undefined; } if (!error || expectedException(actual, error)) { diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 66851fa5ea7405..b7eddf94be5e94 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -199,32 +199,40 @@ a.throws(() => thrower(TypeError), (err) => { const noop = () => {}; assert.throws( () => { a.throws((noop)); }, - common.expectsError({ + { code: 'ERR_ASSERTION', - message: /^Missing expected exception\.$/, - operator: 'throws' - })); + message: 'Missing expected exception.', + operator: 'throws', + actual: undefined, + expected: undefined + }); assert.throws( () => { a.throws(noop, TypeError); }, - common.expectsError({ + { code: 'ERR_ASSERTION', - message: /^Missing expected exception \(TypeError\)\.$/ - })); + message: 'Missing expected exception (TypeError).', + actual: undefined, + expected: TypeError + }); assert.throws( () => { a.throws(noop, 'fhqwhgads'); }, - common.expectsError({ + { code: 'ERR_ASSERTION', - message: /^Missing expected exception: fhqwhgads$/ - })); + message: 'Missing expected exception: fhqwhgads', + actual: undefined, + expected: undefined + }); assert.throws( () => { a.throws(noop, TypeError, 'fhqwhgads'); }, - common.expectsError({ + { code: 'ERR_ASSERTION', - message: /^Missing expected exception \(TypeError\): fhqwhgads$/ - })); + message: 'Missing expected exception (TypeError): fhqwhgads', + actual: undefined, + expected: TypeError + }); let threw = false; try {