mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
test: add tests for validateNumber/validateString
PR-URL: https://github.com/nodejs/node/pull/34672 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Pranshu Srivastava <rexagod@gmail.com> Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
1 parent
84ef92f7cb
commit
6914b3798c
1 file changed
+23
@@ -7,7 +7,9 @@ const {
|
||||
validateArray,
|
||||
validateBoolean,
|
||||
validateInteger,
|
||||
validateNumber,
|
||||
validateObject,
|
||||
validateString,
|
||||
} = require('internal/validators');
|
||||
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number;
|
||||
const outOfRangeError = {
|
||||
@@ -85,3 +87,24 @@ const invalidArgValueError = {
|
||||
|
||||
validateObject(null, 'foo', { nullable: true });
|
||||
}
|
||||
|
||||
{
|
||||
// validateString type validation.
|
||||
[
|
||||
-1, {}, [], false, true,
|
||||
1, Infinity, -Infinity, NaN,
|
||||
undefined, null, 1.1
|
||||
].forEach((i) => assert.throws(() => validateString(i, 'name'), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
}));
|
||||
}
|
||||
{
|
||||
// validateNumber type validation.
|
||||
[
|
||||
'a', {}, [], false, true,
|
||||
undefined, null, '', ' ', '0x',
|
||||
'-0x1', '-0o1', '-0b1', '0o', '0b'
|
||||
].forEach((i) => assert.throws(() => validateNumber(i, 'name'), {
|
||||
code: 'ERR_INVALID_ARG_TYPE'
|
||||
}));
|
||||
}
|
||||
Reference in new issue
Block a user