From a750e133020b1226f6714772a5f69df3fff57d5b Mon Sep 17 00:00:00 2001 From: starkwang <381152119@qq.com> Date: Sat, 1 Jul 2017 23:56:38 +0800 Subject: [PATCH] path: Fix the error message of path.format --- lib/path.js | 4 ++-- test/parallel/test-path-format-error.js | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 test/parallel/test-path-format-error.js diff --git a/lib/path.js b/lib/path.js index f8d0e822bf1d9b..f7d02b992f626d 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-format-error.js b/test/parallel/test-path-format-error.js new file mode 100644 index 00000000000000..32a2a079b77600 --- /dev/null +++ b/test/parallel/test-path-format-error.js @@ -0,0 +1,22 @@ +'use strict'; +const common = require('../common'); +const path = require('path'); +const assert = require('assert'); + +const invalidInput = [ + 111, + 'foo', + undefined, + () => {} +]; +invalidInput.forEach((val) => { + const err = common.expectsError({ + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "pathObject" argument must be of type Object. ' + + `Received type ${typeof val}` + }); + assert.throws(function() { + path.format(val); + }, err); +});