Skip to content

Commit 25226ce

Browse files
cjihrigitaloacasas
authored andcommitted
test: improve checks in test-path-parse-format
- validate full error messages - use assert.throws() instead of try...catch PR-URL: #11223 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 445794e commit 25226ce

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

test/parallel/test-path-parse-format.js

+16-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
const common = require('../common');
2+
require('../common');
33
const assert = require('assert');
44
const path = require('path');
55

@@ -69,23 +69,27 @@ const unixSpecialCaseFormatTests = [
6969

7070
const errors = [
7171
{method: 'parse', input: [null],
72-
message: /Path must be a string. Received null/},
72+
message: /^TypeError: Path must be a string. Received null$/},
7373
{method: 'parse', input: [{}],
74-
message: /Path must be a string. Received {}/},
74+
message: /^TypeError: Path must be a string. Received {}$/},
7575
{method: 'parse', input: [true],
76-
message: /Path must be a string. Received true/},
76+
message: /^TypeError: Path must be a string. Received true$/},
7777
{method: 'parse', input: [1],
78-
message: /Path must be a string. Received 1/},
78+
message: /^TypeError: Path must be a string. Received 1$/},
7979
{method: 'parse', input: [],
80-
message: /Path must be a string. Received undefined/},
80+
message: /^TypeError: Path must be a string. Received undefined$/},
8181
{method: 'format', input: [null],
82-
message: /Parameter "pathObject" must be an object, not/},
82+
message:
83+
/^TypeError: Parameter "pathObject" must be an object, not object$/},
8384
{method: 'format', input: [''],
84-
message: /Parameter "pathObject" must be an object, not string/},
85+
message:
86+
/^TypeError: Parameter "pathObject" must be an object, not string$/},
8587
{method: 'format', input: [true],
86-
message: /Parameter "pathObject" must be an object, not boolean/},
88+
message:
89+
/^TypeError: Parameter "pathObject" must be an object, not boolean$/},
8790
{method: 'format', input: [1],
88-
message: /Parameter "pathObject" must be an object, not number/},
91+
message:
92+
/^TypeError: Parameter "pathObject" must be an object, not number$/},
8993
];
9094

9195
checkParseFormat(path.win32, winPaths);
@@ -158,18 +162,9 @@ assert.strictEqual(failures.length, 0, failures.join(''));
158162

159163
function checkErrors(path) {
160164
errors.forEach(function(errorCase) {
161-
try {
165+
assert.throws(() => {
162166
path[errorCase.method].apply(path, errorCase.input);
163-
} catch (err) {
164-
assert.ok(err instanceof TypeError);
165-
assert.ok(
166-
errorCase.message.test(err.message),
167-
'expected ' + errorCase.message + ' to match ' + err.message
168-
);
169-
return;
170-
}
171-
172-
common.fail('should have thrown');
167+
}, errorCase.message);
173168
});
174169
}
175170

0 commit comments

Comments
 (0)