Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: replace assert.throws with expectsError #17997

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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'
}
);
});