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.

Backport-PR-URL: #19230
PR-URL: #17703
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and MylesBorins committed Mar 13, 2018
1 parent 6b71431 commit c83f1b1
Showing 1 changed file with 18 additions and 36 deletions.
54 changes: 18 additions & 36 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
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 c83f1b1

Please sign in to comment.