diff options
author | cjihrig <cjihrig@gmail.com> | 2017-02-07 13:26:26 -0500 |
---|---|---|
committer | cjihrig <cjihrig@gmail.com> | 2017-02-09 13:17:36 -0500 |
commit | 0700927832e167ac83183aefa0f63af02b6c3a75 (patch) | |
tree | ec9b66d40653e8bfca60d6f437d8fe69ff88dd1c /test/parallel/test-path-parse-format.js | |
parent | 8514269876c4250e885a1b2407cfa7eb92498c0e (diff) | |
download | android-node-v8-0700927832e167ac83183aefa0f63af02b6c3a75.tar.gz android-node-v8-0700927832e167ac83183aefa0f63af02b6c3a75.tar.bz2 android-node-v8-0700927832e167ac83183aefa0f63af02b6c3a75.zip |
test: improve checks in test-path-parse-format
- validate full error messages
- use assert.throws() instead of try...catch
PR-URL: https://github.com/nodejs/node/pull/11223
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Diffstat (limited to 'test/parallel/test-path-parse-format.js')
-rw-r--r-- | test/parallel/test-path-parse-format.js | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/test/parallel/test-path-parse-format.js b/test/parallel/test-path-parse-format.js index ac0cf62117..9d5c149924 100644 --- a/test/parallel/test-path-parse-format.js +++ b/test/parallel/test-path-parse-format.js @@ -1,5 +1,5 @@ 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const path = require('path'); @@ -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); @@ -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); }); } |