Skip to content

Commit

Permalink
assert: fix misformatted error message
Browse files Browse the repository at this point in the history
Before: `Missing expected exception..`

Afer: `Missing expected exception.`

PR-URL: #11254
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
  • Loading branch information
Trott committed Feb 15, 2017
1 parent 4b8b7e9 commit 0af4183
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 24 additions & 1 deletion test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,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;

Expand Down Expand Up @@ -535,7 +558,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
});
} catch (e) {
threw = true;
assert.strictEqual(e.message, 'Missing expected exception..');
assert.strictEqual(e.message, 'Missing expected exception.');
}
assert.ok(threw);
}
Expand Down

0 comments on commit 0af4183

Please sign in to comment.