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: https://github.com/nodejs/node/pull/17575
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
This commit is contained in:
Ruben Bridgewater 2017-12-09 14:05:20 -02:00
parent 897f457f5d
commit a6788b407b
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762
2 changed files with 13 additions and 7 deletions

View File

@ -180,7 +180,7 @@ function innerThrows(shouldThrow, block, expected, message) {
details += ` (${expected.name})`;
}
details += message ? `: ${message}` : '.';
fail(actual, expected, `Missing expected exception${details}`, fail);
fail(actual, expected, `Missing expected exception${details}`, 'throws');
}
if (expected && expectedException(actual, expected) === false) {
throw actual;
@ -191,7 +191,7 @@ function innerThrows(shouldThrow, block, expected, message) {
fail(actual,
expected,
`Got unwanted exception${details}\n${actual.message}`,
fail);
'doesNotThrow');
}
throw actual;
}

View File

@ -466,10 +466,15 @@ assert.throws(() => { assert.ifError(new Error('test error')); },
assert.doesNotThrow(() => { assert.ifError(null); });
assert.doesNotThrow(() => { assert.ifError(); });
assert.throws(() => {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
}, /Got unwanted exception: user message/,
'a.doesNotThrow ignores user message');
common.expectsError(
() => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
{
type: a.AssertionError,
code: 'ERR_ASSERTION',
operator: 'doesNotThrow',
message: 'Got unwanted exception: user message\n[object Object]'
}
);
{
let threw = false;
@ -556,7 +561,8 @@ a.throws(makeBlock(thrower, TypeError), (err) => {
() => { a.throws((noop)); },
common.expectsError({
code: 'ERR_ASSERTION',
message: /^Missing expected exception\.$/
message: /^Missing expected exception\.$/,
operator: 'throws'
}));
assert.throws(