Skip to content

Commit ec443c3

Browse files
BridgeARMylesBorins
authored andcommitted
assert: fix .throws operator
assert.throws and assert.doesNotThrow set the operator to a internal function. That was by accident and originally the operator was undefined. This changes it to show "throws" or "doesNotThrow". PR-URL: #17575 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]>
1 parent ed7f59a commit ec443c3

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/assert.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ function innerThrows(shouldThrow, block, expected, message) {
183183
details += ` (${expected.name})`;
184184
}
185185
details += message ? `: ${message}` : '.';
186-
fail(actual, expected, `Missing expected exception${details}`, fail);
186+
fail(actual, expected, `Missing expected exception${details}`, 'throws');
187187
}
188188
if (expected && expectedException(actual, expected) === false) {
189189
throw actual;
@@ -194,7 +194,7 @@ function innerThrows(shouldThrow, block, expected, message) {
194194
fail(actual,
195195
expected,
196196
`Got unwanted exception${details}\n${actual.message}`,
197-
fail);
197+
'doesNotThrow');
198198
}
199199
throw actual;
200200
}

test/parallel/test-assert.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); },
466466
assert.doesNotThrow(() => { assert.ifError(null); });
467467
assert.doesNotThrow(() => { assert.ifError(); });
468468

469-
assert.throws(() => {
470-
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
471-
}, /Got unwanted exception: user message/,
472-
'a.doesNotThrow ignores user message');
469+
common.expectsError(
470+
() => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
471+
{
472+
type: a.AssertionError,
473+
code: 'ERR_ASSERTION',
474+
operator: 'doesNotThrow',
475+
message: 'Got unwanted exception: user message\n[object Object]'
476+
}
477+
);
473478

474479
{
475480
let threw = false;
@@ -556,7 +561,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => {
556561
() => { a.throws((noop)); },
557562
common.expectsError({
558563
code: 'ERR_ASSERTION',
559-
message: /^Missing expected exception\.$/
564+
message: /^Missing expected exception\.$/,
565+
operator: 'throws'
560566
}));
561567

562568
assert.throws(

0 commit comments

Comments
 (0)