test: refactor common.expectsError

A combination of try catch and common.expectsError is not necessary
as the latter already does everything on its own.

PR-URL: https://github.com/nodejs/node/pull/17703
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Ruben Bridgewater 2017-12-15 21:10:35 -02:00
parent d9171fef3f
commit dc2e266647
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -476,33 +476,21 @@ common.expectsError(
} }
); );
{ common.expectsError(
let threw = false; () => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
try { {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message'); code: 'ERR_ASSERTION',
} catch (e) { message: /Got unwanted exception: user message\n\[object Object\]/
threw = true;
common.expectsError({
code: 'ERR_ASSERTION',
message: /Got unwanted exception: user message\n\[object Object\]/
})(e);
} }
assert.ok(threw); );
}
{ common.expectsError(
let threw = false; () => assert.doesNotThrow(makeBlock(thrower, Error)),
try { {
assert.doesNotThrow(makeBlock(thrower, Error)); code: 'ERR_ASSERTION',
} catch (e) { message: /Got unwanted exception\.\n\[object Object\]/
threw = true;
common.expectsError({
code: 'ERR_ASSERTION',
message: /Got unwanted exception\.\n\[object Object\]/
})(e);
} }
assert.ok(threw); );
}
// make sure that validating using constructor really works // make sure that validating using constructor really works
{ {
@ -691,21 +679,15 @@ try {
} }
const testBlockTypeError = (method, block) => { const testBlockTypeError = (method, block) => {
let threw = true; common.expectsError(
() => method(block),
try { {
method(block);
threw = false;
} catch (e) {
common.expectsError({
code: 'ERR_INVALID_ARG_TYPE', code: 'ERR_INVALID_ARG_TYPE',
type: TypeError, type: TypeError,
message: 'The "block" argument must be of type Function. Received ' + message: 'The "block" argument must be of type Function. Received ' +
`type ${typeName(block)}` `type ${typeName(block)}`
})(e); }
} );
assert.ok(threw);
}; };
testBlockTypeError(assert.throws, 'string'); testBlockTypeError(assert.throws, 'string');