From 7969811a88a5f0a33c51ffe4078a9ec28a19906d Mon Sep 17 00:00:00 2001 From: sreepurnajasti Date: Fri, 5 Jan 2018 13:13:51 +0530 Subject: test: replace assert.throws with expectsError PR-URL: https://github.com/nodejs/node/pull/17997 Reviewed-By: Luigi Pinca Reviewed-By: James M Snell Reviewed-By: Ruben Bridgewater --- test/parallel/test-http-response-statuscode.js | 7 +++---- test/parallel/test-url-format-invalid-input.js | 5 +++-- test/parallel/test-url-parse-invalid-input.js | 5 +++-- test/parallel/test-util-inherits.js | 21 ++++++++++----------- 4 files changed, 19 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/parallel/test-http-response-statuscode.js b/test/parallel/test-http-response-statuscode.js index 79c3f63054..7e93ad10a9 100644 --- a/test/parallel/test-http-response-statuscode.js +++ b/test/parallel/test-http-response-statuscode.js @@ -8,14 +8,13 @@ const MAX_REQUESTS = 13; let reqNum = 0; function test(res, header, code) { - const errRegExp = common.expectsError({ + common.expectsError(() => { + res.writeHead(header); + }, { code: 'ERR_HTTP_INVALID_STATUS_CODE', type: RangeError, message: `Invalid status code: ${code}` }); - assert.throws(() => { - res.writeHead(header); - }, errRegExp); } const server = http.Server(common.mustCall(function(req, res) { diff --git a/test/parallel/test-url-format-invalid-input.js b/test/parallel/test-url-format-invalid-input.js index a94546aaf2..4f0f1a11d7 100644 --- a/test/parallel/test-url-format-invalid-input.js +++ b/test/parallel/test-url-format-invalid-input.js @@ -14,13 +14,14 @@ const throwsObjsAndReportTypes = new Map([ ]); for (const [urlObject, type] of throwsObjsAndReportTypes) { - const error = common.expectsError({ + common.expectsError(function() { + url.format(urlObject); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "urlObject" argument must be one of type Object or string. ' + `Received type ${type}` }); - assert.throws(function() { url.format(urlObject); }, error); } assert.strictEqual(url.format(''), ''); assert.strictEqual(url.format({}), ''); diff --git a/test/parallel/test-url-parse-invalid-input.js b/test/parallel/test-url-parse-invalid-input.js index 86751a2935..d2c7a1135a 100644 --- a/test/parallel/test-url-parse-invalid-input.js +++ b/test/parallel/test-url-parse-invalid-input.js @@ -16,12 +16,13 @@ const url = require('url'); [() => {}, 'function'], [Symbol('foo'), 'symbol'] ].forEach(([val, type]) => { - const error = common.expectsError({ + common.expectsError(() => { + url.parse(val); + }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: `The "url" argument must be of type string. Received type ${type}` }); - assert.throws(() => { url.parse(val); }, error); }); assert.throws(() => { url.parse('http://%E0%A4%A@fail'); }, diff --git a/test/parallel/test-util-inherits.js b/test/parallel/test-util-inherits.js index 9c610e3800..afbd504beb 100644 --- a/test/parallel/test-util-inherits.js +++ b/test/parallel/test-util-inherits.js @@ -3,11 +3,6 @@ const common = require('../common'); const assert = require('assert'); const inherits = require('util').inherits; -const errCheck = common.expectsError({ - code: 'ERR_INVALID_ARG_TYPE', - type: TypeError, - message: 'The "superCtor" argument must be of type Function' -}); // super constructor function A() { @@ -86,16 +81,20 @@ common.expectsError(function() { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "superCtor.prototype" property must be of type Function' -} -); -assert.throws(function() { +}); + +common.expectsError(function() { inherits(A, null); -}, errCheck); +}, { + code: 'ERR_INVALID_ARG_TYPE', + type: TypeError, + message: 'The "superCtor" argument must be of type Function' +}); + common.expectsError(function() { inherits(null, A); }, { code: 'ERR_INVALID_ARG_TYPE', type: TypeError, message: 'The "ctor" argument must be of type Function' -} -); +}); -- cgit v1.2.3