Skip to content

Commit

Permalink
test: refactor common.expectsError
Browse files Browse the repository at this point in the history
A combination of try catch and common.expectsError is not necessary
as the latter already does everything on its own.

PR-URL: nodejs#17703
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR committed Mar 8, 2018
1 parent 9664cc8 commit 0ed963b
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions test/parallel/test-assert.js
Expand Up @@ -476,33 +476,21 @@ common.expectsError(
}
);

{
let threw = false;
try {
assert.doesNotThrow(makeBlock(thrower, Error), 'user message');
} catch (e) {
threw = true;
common.expectsError({
code: 'ERR_ASSERTION',
message: /Got unwanted exception: user message\n\[object Object\]/
})(e);
common.expectsError(
() => assert.doesNotThrow(makeBlock(thrower, Error), 'user message'),
{
code: 'ERR_ASSERTION',
message: /Got unwanted exception: user message\n\[object Object\]/
}
assert.ok(threw);
}
);

{
let threw = false;
try {
assert.doesNotThrow(makeBlock(thrower, Error));
} catch (e) {
threw = true;
common.expectsError({
code: 'ERR_ASSERTION',
message: /Got unwanted exception\.\n\[object Object\]/
})(e);
common.expectsError(
() => assert.doesNotThrow(makeBlock(thrower, Error)),
{
code: 'ERR_ASSERTION',
message: /Got unwanted exception\.\n\[object Object\]/
}
assert.ok(threw);
}
);

// make sure that validating using constructor really works
{
Expand Down Expand Up @@ -691,21 +679,15 @@ try {
}

const testBlockTypeError = (method, block) => {
let threw = true;

try {
method(block);
threw = false;
} catch (e) {
common.expectsError({
common.expectsError(
() => method(block),
{
code: 'ERR_INVALID_ARG_TYPE',
type: TypeError,
message: 'The "block" argument must be of type Function. Received ' +
`type ${typeName(block)}`
})(e);
}

assert.ok(threw);
`type ${typeName(block)}`
}
);
};

testBlockTypeError(assert.throws, 'string');
Expand Down

0 comments on commit 0ed963b

Please sign in to comment.