Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve checks in test-path-parse-format #11223

Merged
merged 1 commit into from
Feb 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions test/parallel/test-path-parse-format.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
const common = require('../common');
require('../common');
const assert = require('assert');
const path = require('path');

Expand Down Expand Up @@ -69,23 +69,27 @@ const unixSpecialCaseFormatTests = [

const errors = [
{method: 'parse', input: [null],
message: /Path must be a string. Received null/},
message: /^TypeError: Path must be a string. Received null$/},
{method: 'parse', input: [{}],
message: /Path must be a string. Received {}/},
message: /^TypeError: Path must be a string. Received {}$/},
{method: 'parse', input: [true],
message: /Path must be a string. Received true/},
message: /^TypeError: Path must be a string. Received true$/},
{method: 'parse', input: [1],
message: /Path must be a string. Received 1/},
message: /^TypeError: Path must be a string. Received 1$/},
{method: 'parse', input: [],
message: /Path must be a string. Received undefined/},
message: /^TypeError: Path must be a string. Received undefined$/},
{method: 'format', input: [null],
message: /Parameter "pathObject" must be an object, not/},
message:
/^TypeError: Parameter "pathObject" must be an object, not object$/},
{method: 'format', input: [''],
message: /Parameter "pathObject" must be an object, not string/},
message:
/^TypeError: Parameter "pathObject" must be an object, not string$/},
{method: 'format', input: [true],
message: /Parameter "pathObject" must be an object, not boolean/},
message:
/^TypeError: Parameter "pathObject" must be an object, not boolean$/},
{method: 'format', input: [1],
message: /Parameter "pathObject" must be an object, not number/},
message:
/^TypeError: Parameter "pathObject" must be an object, not number$/},
];

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

function checkErrors(path) {
errors.forEach(function(errorCase) {
try {
assert.throws(() => {
path[errorCase.method].apply(path, errorCase.input);
} catch (err) {
assert.ok(err instanceof TypeError);
assert.ok(
errorCase.message.test(err.message),
'expected ' + errorCase.message + ' to match ' + err.message
);
return;
}

common.fail('should have thrown');
}, errorCase.message);
});
}

Expand Down