From 7eb431a6f82a3c21860b82c52e8669eb2993ddeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 30 Jun 2017 21:30:23 +0200 Subject: [PATCH 1/4] assert: fix incorrect use of ERR_INVALID_ARG_TYPE --- lib/assert.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/assert.js b/lib/assert.js index bd36c9a16d1b38..ff610e8389f2ec 100644 --- a/lib/assert.js +++ b/lib/assert.js @@ -536,7 +536,7 @@ function _throws(shouldThrow, block, expected, message) { if (typeof block !== 'function') { const errors = lazyErrors(); throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'block', 'function', - typeof block); + block); } if (typeof expected === 'string') { From 35125bb2340ac8fa0ed9ded4fff3a6a8dddb01a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 30 Jun 2017 21:31:21 +0200 Subject: [PATCH 2/4] path: fix incorrect use of ERR_INVALID_ARG_TYPE --- lib/path.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/path.js b/lib/path.js index f8d0e822bf1d9b..001152866ffc35 100644 --- a/lib/path.js +++ b/lib/path.js @@ -960,7 +960,7 @@ const win32 = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', - typeof pathObject); + pathObject); } return _format('\\', pathObject); }, @@ -1503,7 +1503,7 @@ const posix = { format: function format(pathObject) { if (pathObject === null || typeof pathObject !== 'object') { throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'pathObject', 'Object', - typeof pathObject); + pathObject); } return _format('/', pathObject); }, From 2adb42229702af2e0d71bf125853acb41bd73980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 30 Jun 2017 21:52:31 +0200 Subject: [PATCH 3/4] add tests for assert --- test/parallel/test-assert.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 561ce6d79b4af3..0054705df451ac 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -669,10 +669,9 @@ try { { // Verify that throws() and doesNotThrow() throw on non-function block - const validationFunction = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError - }); + function typeName(value) { + return value === null ? 'null' : typeof value; + } const testBlockTypeError = (method, block) => { let threw = true; @@ -681,7 +680,12 @@ try { method(block); threw = false; } catch (e) { - validationFunction(e); + common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "block" argument must be of type function. Received ' + + 'type ' + typeName(block) + })(e); } assert.ok(threw); From f44bbfcf636794066674945d3472559af9e639d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20Nie=C3=9Fen?= Date: Fri, 30 Jun 2017 21:53:01 +0200 Subject: [PATCH 4/4] add tests for path.format --- test/parallel/test-path-parse-format.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 05335b8f308341..0401c73f96bb5b 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -207,4 +207,19 @@ function checkFormat(path, testCases) { testCases.forEach(function(testCase) { assert.strictEqual(path.format(testCase[0]), testCase[1]); }); + + function typeName(value) { + return value === null ? 'null' : typeof value; + } + + [null, undefined, 1, true, false, 'string'].forEach((pathObject) => { + assert.throws(() => { + path.format(pathObject); + }, common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "pathObject" argument must be of type Object. Received ' + + 'type ' + typeName(pathObject) + })); + }); }