Permalink
Browse files

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>
  • Loading branch information...
Trott committed Feb 9, 2017
1 parent 4b8b7e9 commit 0af41834f11a1dff7399eb734c5cabcd756051ab
Showing with 26 additions and 3 deletions.
  1. +2 −2 lib/assert.js
  2. +24 −1 test/parallel/test-assert.js
View
@@ -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);
@@ -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;
@@ -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);
}

0 comments on commit 0af4183

Please sign in to comment.