Skip to content

Commit 093a4b0

Browse files
lundibundiBethGriggs
authored andcommitted
test: add tests for validateNumber/validateString
PR-URL: #34672 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]> Reviewed-By: Pranshu Srivastava <[email protected]> Reviewed-By: Ricky Zhou <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent aaa6e43 commit 093a4b0

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

test/parallel/test-validators.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ const {
77
validateArray,
88
validateBoolean,
99
validateInteger,
10+
validateNumber,
1011
validateObject,
12+
validateString,
1113
} = require('internal/validators');
1214
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number;
1315
const outOfRangeError = {
@@ -85,3 +87,24 @@ const invalidArgValueError = {
8587

8688
validateObject(null, 'foo', { nullable: true });
8789
}
90+
91+
{
92+
// validateString type validation.
93+
[
94+
-1, {}, [], false, true,
95+
1, Infinity, -Infinity, NaN,
96+
undefined, null, 1.1
97+
].forEach((i) => assert.throws(() => validateString(i, 'name'), {
98+
code: 'ERR_INVALID_ARG_TYPE'
99+
}));
100+
}
101+
{
102+
// validateNumber type validation.
103+
[
104+
'a', {}, [], false, true,
105+
undefined, null, '', ' ', '0x',
106+
'-0x1', '-0o1', '-0b1', '0o', '0b'
107+
].forEach((i) => assert.throws(() => validateNumber(i, 'name'), {
108+
code: 'ERR_INVALID_ARG_TYPE'
109+
}));
110+
}

0 commit comments

Comments
 (0)