Skip to content

Commit 46084e3

Browse files
Trottitaloacasas
authored andcommittedFeb 25, 2017
test: refactor common.expectsError()
* Report values in assertions. * Strict equality match if message is a string. * instanceof/typeof instead of deprecated util.isRegExp() PR-URL: #11381 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 5f10827 commit 46084e3

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed
 

‎test/common.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,13 @@ exports.expectsError = function expectsError(code, type, message) {
626626
return function(error) {
627627
assert.strictEqual(error.code, code);
628628
if (type !== undefined)
629-
assert(error instanceof type, 'error is not the expected type');
630-
if (message !== undefined) {
631-
if (!util.isRegExp(message))
632-
message = new RegExp(String(message));
633-
assert(message.test(error.message), 'error.message does not match');
629+
assert(error instanceof type,
630+
`${error} is not the expected type ${type}`);
631+
if (message instanceof RegExp) {
632+
assert(message.test(error.message),
633+
`${error.message} does not match ${message}`);
634+
} else if (typeof message === 'string') {
635+
assert.strictEqual(error.message, message);
634636
}
635637
return true;
636638
};

‎test/parallel/test-internal-errors.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ assert.throws(() => {
107107
assert.throws(() => {
108108
throw new errors.TypeError('TEST_ERROR_1', 'a');
109109
}, common.expectsError('TEST_ERROR_1', RangeError));
110-
}, /^AssertionError: error is not the expected type/);
110+
}, /^AssertionError: .+ is not the expected type \S/);
111111

112112
assert.throws(() => {
113113
assert.throws(() => {
114114
throw new errors.TypeError('TEST_ERROR_1', 'a');
115115
}, common.expectsError('TEST_ERROR_1', TypeError, /^Error for testing 2/));
116-
}, /^AssertionError: error.message does not match/);
116+
}, /AssertionError: .+ does not match \S/);

0 commit comments

Comments
 (0)
Please sign in to comment.