|
1 | 1 | 'use strict';
|
2 |
| -const common = require('../common'); |
| 2 | +require('../common'); |
3 | 3 | const assert = require('assert');
|
4 | 4 | const path = require('path');
|
5 | 5 |
|
@@ -69,23 +69,27 @@ const unixSpecialCaseFormatTests = [
|
69 | 69 |
|
70 | 70 | const errors = [
|
71 | 71 | {method: 'parse', input: [null],
|
72 |
| - message: /Path must be a string. Received null/}, |
| 72 | + message: /^TypeError: Path must be a string. Received null$/}, |
73 | 73 | {method: 'parse', input: [{}],
|
74 |
| - message: /Path must be a string. Received {}/}, |
| 74 | + message: /^TypeError: Path must be a string. Received {}$/}, |
75 | 75 | {method: 'parse', input: [true],
|
76 |
| - message: /Path must be a string. Received true/}, |
| 76 | + message: /^TypeError: Path must be a string. Received true$/}, |
77 | 77 | {method: 'parse', input: [1],
|
78 |
| - message: /Path must be a string. Received 1/}, |
| 78 | + message: /^TypeError: Path must be a string. Received 1$/}, |
79 | 79 | {method: 'parse', input: [],
|
80 |
| - message: /Path must be a string. Received undefined/}, |
| 80 | + message: /^TypeError: Path must be a string. Received undefined$/}, |
81 | 81 | {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$/}, |
83 | 84 | {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$/}, |
85 | 87 | {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$/}, |
87 | 90 | {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$/}, |
89 | 93 | ];
|
90 | 94 |
|
91 | 95 | checkParseFormat(path.win32, winPaths);
|
@@ -158,18 +162,9 @@ assert.strictEqual(failures.length, 0, failures.join(''));
|
158 | 162 |
|
159 | 163 | function checkErrors(path) {
|
160 | 164 | errors.forEach(function(errorCase) {
|
161 |
| - try { |
| 165 | + assert.throws(() => { |
162 | 166 | 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); |
173 | 168 | });
|
174 | 169 | }
|
175 | 170 |
|
|
0 commit comments