Skip to content

Commit

Permalink
test: replace assert.throws with expectsError
Browse files Browse the repository at this point in the history
PR-URL: #17997
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
sreepurnajasti authored and addaleax committed Feb 27, 2018
1 parent df0d78a commit 1be5e33
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
7 changes: 3 additions & 4 deletions test/parallel/test-http-response-statuscode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions test/parallel/test-url-format-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({}), '');
5 changes: 3 additions & 2 deletions test/parallel/test-url-parse-invalid-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'); },
Expand Down
21 changes: 10 additions & 11 deletions test/parallel/test-util-inherits.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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'
}
);
});

0 comments on commit 1be5e33

Please sign in to comment.