Skip to content

Commit 0af4183

Browse files
committed
assert: fix misformatted error message
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>
1 parent 4b8b7e9 commit 0af4183

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,8 @@ function _throws(shouldThrow, block, expected, message) {
341341

342342
actual = _tryBlock(block);
343343

344-
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') +
345-
(message ? ' ' + message : '.');
344+
message = (expected && expected.name ? ' (' + expected.name + ')' : '') +
345+
(message ? ': ' + message : '.');
346346

347347
if (shouldThrow && !actual) {
348348
fail(actual, expected, 'Missing expected exception' + message);

test/parallel/test-assert.js

+24-1
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,29 @@ a.throws(makeBlock(a.deepEqual, args, []));
490490
a.doesNotThrow(makeBlock(a.deepEqual, someArgs, sameArgs));
491491
}
492492

493+
// check messages from assert.throws()
494+
{
495+
assert.throws(
496+
() => { a.throws(() => {}); },
497+
/^AssertionError: Missing expected exception\.$/
498+
);
499+
500+
assert.throws(
501+
() => { a.throws(() => {}, TypeError); },
502+
/^AssertionError: Missing expected exception \(TypeError\)\.$/
503+
);
504+
505+
assert.throws(
506+
() => { a.throws(() => {}, 'fhqwhgads'); },
507+
/^AssertionError: Missing expected exception: fhqwhgads$/
508+
);
509+
510+
assert.throws(
511+
() => { a.throws(() => {}, TypeError, 'fhqwhgads'); },
512+
/^AssertionError: Missing expected exception \(TypeError\): fhqwhgads$/
513+
);
514+
}
515+
493516
const circular = {y: 1};
494517
circular.x = circular;
495518

@@ -535,7 +558,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
535558
});
536559
} catch (e) {
537560
threw = true;
538-
assert.strictEqual(e.message, 'Missing expected exception..');
561+
assert.strictEqual(e.message, 'Missing expected exception.');
539562
}
540563
assert.ok(threw);
541564
}

0 commit comments

Comments
 (0)