Skip to content

Commit

Permalink
test: add tests for validateNumber/validateString
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
lundibundi authored and Trott committed Aug 9, 2020
1 parent 84ef92f commit 6914b37
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions test/parallel/test-validators.js
Expand Up @@ -7,7 +7,9 @@ const {
validateArray,
validateBoolean,
validateInteger,
validateNumber,
validateObject,
validateString,
} = require('internal/validators');
const { MAX_SAFE_INTEGER, MIN_SAFE_INTEGER } = Number;
const outOfRangeError = {
Expand Down Expand Up @@ -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'
}));
}

0 comments on commit 6914b37

Please sign in to comment.