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(); test_error.throwTypeError();
}, /^TypeError: type error$/); }, /^TypeError: type error$/);
function testThrowArbitrary(value) { [42, {}, [], Symbol('xyzzy'), true, 'ball', undefined, null, NaN]
assert.throws( .forEach((value) => assert.throws(
() => test_error.throwArbitrary(value), () => test_error.throwArbitrary(value),
(err) => { (err) => {
assert.strictEqual(err, value); assert.strictEqual(err, value);
return true; return true;
}); }
} ));
testThrowArbitrary(42);
testThrowArbitrary({});
testThrowArbitrary([]);
testThrowArbitrary(Symbol('xyzzy'));
testThrowArbitrary(true);
testThrowArbitrary('ball');
testThrowArbitrary(undefined);
testThrowArbitrary(null);
testThrowArbitrary(NaN);
common.expectsError( common.expectsError(
() => test_error.throwErrorCode(), () => test_error.throwErrorCode(),