Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1be5e33

Browse filesBrowse files
sreepurnajastiaddaleax
authored andcommitted
test: replace assert.throws with expectsError
PR-URL: #17997 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent df0d78a commit 1be5e33
Copy full SHA for 1be5e33

File tree

Expand file treeCollapse file tree

4 files changed

+19
-19
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+19
-19
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-http-response-statuscode.js
+3-4Lines changed: 3 additions & 4 deletions
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) {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-url-format-invalid-input.js
+3-2Lines changed: 3 additions & 2 deletions
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({}), '');
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-url-parse-invalid-input.js
+3-2Lines changed: 3 additions & 2 deletions
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'); },
Collapse file

‎test/parallel/test-util-inherits.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-util-inherits.js
+10-11Lines changed: 10 additions & 11 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.