test: replace assert.throws with expectsError
PR-URL: https://github.com/nodejs/node/pull/17997 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
bcb01de515
commit
7969811a88
@ -8,14 +8,13 @@ const MAX_REQUESTS = 13;
|
|||||||
let reqNum = 0;
|
let reqNum = 0;
|
||||||
|
|
||||||
function test(res, header, code) {
|
function test(res, header, code) {
|
||||||
const errRegExp = common.expectsError({
|
common.expectsError(() => {
|
||||||
|
res.writeHead(header);
|
||||||
|
}, {
|
||||||
code: 'ERR_HTTP_INVALID_STATUS_CODE',
|
code: 'ERR_HTTP_INVALID_STATUS_CODE',
|
||||||
type: RangeError,
|
type: RangeError,
|
||||||
message: `Invalid status code: ${code}`
|
message: `Invalid status code: ${code}`
|
||||||
});
|
});
|
||||||
assert.throws(() => {
|
|
||||||
res.writeHead(header);
|
|
||||||
}, errRegExp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const server = http.Server(common.mustCall(function(req, res) {
|
const server = http.Server(common.mustCall(function(req, res) {
|
||||||
|
@ -14,13 +14,14 @@ const throwsObjsAndReportTypes = new Map([
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
for (const [urlObject, type] of throwsObjsAndReportTypes) {
|
for (const [urlObject, type] of throwsObjsAndReportTypes) {
|
||||||
const error = common.expectsError({
|
common.expectsError(function() {
|
||||||
|
url.format(urlObject);
|
||||||
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "urlObject" argument must be one of type Object or string. ' +
|
message: 'The "urlObject" argument must be one of type Object or string. ' +
|
||||||
`Received type ${type}`
|
`Received type ${type}`
|
||||||
});
|
});
|
||||||
assert.throws(function() { url.format(urlObject); }, error);
|
|
||||||
}
|
}
|
||||||
assert.strictEqual(url.format(''), '');
|
assert.strictEqual(url.format(''), '');
|
||||||
assert.strictEqual(url.format({}), '');
|
assert.strictEqual(url.format({}), '');
|
||||||
|
@ -16,12 +16,13 @@ const url = require('url');
|
|||||||
[() => {}, 'function'],
|
[() => {}, 'function'],
|
||||||
[Symbol('foo'), 'symbol']
|
[Symbol('foo'), 'symbol']
|
||||||
].forEach(([val, type]) => {
|
].forEach(([val, type]) => {
|
||||||
const error = common.expectsError({
|
common.expectsError(() => {
|
||||||
|
url.parse(val);
|
||||||
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: `The "url" argument must be of type string. Received type ${type}`
|
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'); },
|
assert.throws(() => { url.parse('http://%E0%A4%A@fail'); },
|
||||||
|
@ -3,11 +3,6 @@
|
|||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const inherits = require('util').inherits;
|
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
|
// super constructor
|
||||||
function A() {
|
function A() {
|
||||||
@ -86,16 +81,20 @@ common.expectsError(function() {
|
|||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "superCtor.prototype" property must be of type Function'
|
message: 'The "superCtor.prototype" property must be of type Function'
|
||||||
}
|
});
|
||||||
);
|
|
||||||
assert.throws(function() {
|
common.expectsError(function() {
|
||||||
inherits(A, null);
|
inherits(A, null);
|
||||||
}, errCheck);
|
}, {
|
||||||
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
|
type: TypeError,
|
||||||
|
message: 'The "superCtor" argument must be of type Function'
|
||||||
|
});
|
||||||
|
|
||||||
common.expectsError(function() {
|
common.expectsError(function() {
|
||||||
inherits(null, A);
|
inherits(null, A);
|
||||||
}, {
|
}, {
|
||||||
code: 'ERR_INVALID_ARG_TYPE',
|
code: 'ERR_INVALID_ARG_TYPE',
|
||||||
type: TypeError,
|
type: TypeError,
|
||||||
message: 'The "ctor" argument must be of type Function'
|
message: 'The "ctor" argument must be of type Function'
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user