Skip to content

Commit 1be5e33

Browse files
sreepurnajastiaddaleax
authored andcommitted
test: replace assert.throws with expectsError
PR-URL: #17997 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
1 parent df0d78a commit 1be5e33

4 files changed

+19
-19
lines changed

test/parallel/test-http-response-statuscode.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ const MAX_REQUESTS = 13;
88
let reqNum = 0;
99

1010
function test(res, header, code) {
11-
const errRegExp = common.expectsError({
11+
common.expectsError(() => {
12+
res.writeHead(header);
13+
}, {
1214
code: 'ERR_HTTP_INVALID_STATUS_CODE',
1315
type: RangeError,
1416
message: `Invalid status code: ${code}`
1517
});
16-
assert.throws(() => {
17-
res.writeHead(header);
18-
}, errRegExp);
1918
}
2019

2120
const server = http.Server(common.mustCall(function(req, res) {

test/parallel/test-url-format-invalid-input.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ const throwsObjsAndReportTypes = new Map([
1414
]);
1515

1616
for (const [urlObject, type] of throwsObjsAndReportTypes) {
17-
const error = common.expectsError({
17+
common.expectsError(function() {
18+
url.format(urlObject);
19+
}, {
1820
code: 'ERR_INVALID_ARG_TYPE',
1921
type: TypeError,
2022
message: 'The "urlObject" argument must be one of type Object or string. ' +
2123
`Received type ${type}`
2224
});
23-
assert.throws(function() { url.format(urlObject); }, error);
2425
}
2526
assert.strictEqual(url.format(''), '');
2627
assert.strictEqual(url.format({}), '');

test/parallel/test-url-parse-invalid-input.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ const url = require('url');
1616
[() => {}, 'function'],
1717
[Symbol('foo'), 'symbol']
1818
].forEach(([val, type]) => {
19-
const error = common.expectsError({
19+
common.expectsError(() => {
20+
url.parse(val);
21+
}, {
2022
code: 'ERR_INVALID_ARG_TYPE',
2123
type: TypeError,
2224
message: `The "url" argument must be of type string. Received type ${type}`
2325
});
24-
assert.throws(() => { url.parse(val); }, error);
2526
});
2627

2728
assert.throws(() => { url.parse('http://%E0%A4%A@fail'); },

test/parallel/test-util-inherits.js

+10-11
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
const common = require('../common');
44
const assert = require('assert');
55
const inherits = require('util').inherits;
6-
const errCheck = common.expectsError({
7-
code: 'ERR_INVALID_ARG_TYPE',
8-
type: TypeError,
9-
message: 'The "superCtor" argument must be of type Function'
10-
});
116

127
// super constructor
138
function A() {
@@ -86,16 +81,20 @@ common.expectsError(function() {
8681
code: 'ERR_INVALID_ARG_TYPE',
8782
type: TypeError,
8883
message: 'The "superCtor.prototype" property must be of type Function'
89-
}
90-
);
91-
assert.throws(function() {
84+
});
85+
86+
common.expectsError(function() {
9287
inherits(A, null);
93-
}, errCheck);
88+
}, {
89+
code: 'ERR_INVALID_ARG_TYPE',
90+
type: TypeError,
91+
message: 'The "superCtor" argument must be of type Function'
92+
});
93+
9494
common.expectsError(function() {
9595
inherits(null, A);
9696
}, {
9797
code: 'ERR_INVALID_ARG_TYPE',
9898
type: TypeError,
9999
message: 'The "ctor" argument must be of type Function'
100-
}
101-
);
100+
});

0 commit comments

Comments
 (0)