path: fix incorrect use of ERR_INVALID_ARG_TYPE
PR-URL: https://github.com/nodejs/node/pull/14011 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
This commit is contained in:
parent
1d7414354e
commit
44256bb0aa
@ -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);
|
||||
},
|
||||
|
@ -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)
|
||||
}));
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user