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); }, diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index 24e49f3ffc99ea..1c3bdff130f55d 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) + })); + }); }