test: refactoring test_error testing

PR-URL: https://github.com/nodejs/node/pull/28902
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
himself65 2019-07-31 00:53:43 +08:00 committed by Rich Trott
parent f53a241447
commit b32526c488

View File

@ -60,24 +60,14 @@ assert.throws(() => {
test_error.throwTypeError();
}, /^TypeError: type error$/);
function testThrowArbitrary(value) {
assert.throws(
[42, {}, [], Symbol('xyzzy'), true, 'ball', undefined, null, NaN]
.forEach((value) => assert.throws(
() => test_error.throwArbitrary(value),
(err) => {
assert.strictEqual(err, value);
return true;
});
}
testThrowArbitrary(42);
testThrowArbitrary({});
testThrowArbitrary([]);
testThrowArbitrary(Symbol('xyzzy'));
testThrowArbitrary(true);
testThrowArbitrary('ball');
testThrowArbitrary(undefined);
testThrowArbitrary(null);
testThrowArbitrary(NaN);
}
));
common.expectsError(
() => test_error.throwErrorCode(),