From 6914b3798c6c4cc6b2f64a206674505b4b5adf80 Mon Sep 17 00:00:00 2001 From: Denys Otrishko Date: Fri, 7 Aug 2020 13:16:17 +0300 Subject: [PATCH] test: add tests for validateNumber/validateString PR-URL: https://github.com/nodejs/node/pull/34672 Reviewed-By: James M Snell Reviewed-By: Yongsheng Zhang Reviewed-By: Pranshu Srivastava Reviewed-By: Ricky Zhou <0x19951125@gmail.com> Reviewed-By: Luigi Pinca Reviewed-By: Rich Trott --- test/parallel/test-validators.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/parallel/test-validators.js b/test/parallel/test-validators.js index 1c36cc17ec046b..cf4ba17f52e9d7 100644 --- a/test/parallel/test-validators.js +++ b/test/parallel/test-validators.js @@ -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' + })); +}