test: add second argument to assert.throws

This adds RegExp or error constructor arguments to the remaining places
where it is missing in preparation for the commit that will enforce the
presence of at least two arguments.

PR-URL: https://github.com/nodejs/node/pull/12270
Backport-PR-URL: https://github.com/nodejs/node/pull/13785
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
Michaël Zasso authored and Myles Borins committed 2017-07-11 17:43:46 +01:00
1 parent eca9e72a87
commit 2411318f60
5 files changed
+34 -18

No files matched your search

+10 -4
View File
@@ -240,7 +240,8 @@ assert.throws(
{
const re1 = /a/;
re1.lastIndex = 3;
assert.throws(makeBlock(a.deepStrictEqual, re1, /a/));
assert.throws(makeBlock(a.deepStrictEqual, re1, /a/),
/^AssertionError: \/a\/ deepStrictEqual \/a\/$/);
}
// 7.4 - strict
@@ -262,10 +263,12 @@ assert.doesNotThrow(makeBlock(a.deepStrictEqual, {a: 4}, {a: 4}));
assert.doesNotThrow(makeBlock(a.deepStrictEqual,
{a: 4, b: '2'},
{a: 4, b: '2'}));
assert.throws(makeBlock(a.deepStrictEqual, [4], ['4']));
assert.throws(makeBlock(a.deepStrictEqual, [4], ['4']),
/^AssertionError: \[ 4 ] deepStrictEqual \[ '4' ]$/);
assert.throws(makeBlock(a.deepStrictEqual, {a: 4}, {a: 4, b: true}),
a.AssertionError);
assert.throws(makeBlock(a.deepStrictEqual, ['a'], {0: 'a'}));
/^AssertionError: { a: 4 } deepStrictEqual { a: 4, b: true }$/);
assert.throws(makeBlock(a.deepStrictEqual, ['a'], {0: 'a'}),
/^AssertionError: \[ 'a' ] deepStrictEqual { '0': 'a' }$/);
//(although not necessarily the same order),
assert.doesNotThrow(makeBlock(a.deepStrictEqual,
{a: 4, b: '1'},
@@ -342,9 +345,11 @@ function thrower(errorConstructor) {
assert.throws(makeBlock(thrower, a.AssertionError),
a.AssertionError, 'message');
assert.throws(makeBlock(thrower, a.AssertionError), a.AssertionError);
// eslint-disable-next-line assert-throws-arguments
assert.throws(makeBlock(thrower, a.AssertionError));
// if not passing an error, catch all.
// eslint-disable-next-line assert-throws-arguments
assert.throws(makeBlock(thrower, TypeError));
// when passing a type, only catch errors of the appropriate type
@@ -517,6 +522,7 @@ testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
// #2893
try {
// eslint-disable-next-line assert-throws-arguments
assert.throws(function() {
assert.ifError(null);
});
+10 -8
View File
@@ -41,11 +41,11 @@ for (const [key, value] of e.entries()) {
assert.throws(function() {
Buffer(8).fill('a', -1);
});
}, /^RangeError: Out of range index$/);
assert.throws(function() {
Buffer(8).fill('a', 0, 9);
});
}, /^RangeError: Out of range index$/);
// Make sure this doesn't hang indefinitely.
Buffer(8).fill('');
@@ -1433,17 +1433,17 @@ if (common.hasCrypto) {
assert.throws(function() {
const b = Buffer(1);
Buffer.compare(b, 'abc');
});
}, /^TypeError: Arguments must be Buffers$/);
assert.throws(function() {
const b = Buffer(1);
Buffer.compare('abc', b);
});
}, /^TypeError: Arguments must be Buffers$/);
assert.throws(function() {
const b = Buffer(1);
b.compare('abc');
});
}, /^TypeError: Argument must be a Buffer$/);
// Test Equals
{
@@ -1461,10 +1461,12 @@ assert.throws(function() {
assert.throws(function() {
const b = Buffer(1);
b.equals('abc');
});
}, /^TypeError: Argument must be a Buffer$/);
// Regression test for https://github.com/nodejs/node/issues/649.
assert.throws(function() { Buffer(1422561062959).toString('utf8'); });
assert.throws(function() {
Buffer(1422561062959).toString('utf8');
}, /^RangeError: Invalid typed array length$/);
const ps = Buffer.poolSize;
Buffer.poolSize = 0;
@@ -1474,7 +1476,7 @@ Buffer.poolSize = ps;
// Test Buffer.copy() segfault
assert.throws(function() {
Buffer(10).copy();
});
}, /^TypeError: argument should be a Buffer$/);
const regErrorMsg = new RegExp('First argument must be a string, Buffer, ' +
'ArrayBuffer, Array, or array-like object.');
+12 -4
View File
@@ -22,10 +22,18 @@ const cookies = [
const s = http.createServer(function(req, res) {
switch (test) {
case 'headers':
assert.throws(function() { res.setHeader(); });
assert.throws(function() { res.setHeader('someHeader'); });
assert.throws(function() { res.getHeader(); });
assert.throws(function() { res.removeHeader(); });
assert.throws(() => {
res.setHeader();
}, /^TypeError: Header name must be a valid HTTP Token \["undefined"\]$/);
assert.throws(() => {
res.setHeader('someHeader');
}, /^Error: "value" required in setHeader\("someHeader", value\)$/);
assert.throws(() => {
res.getHeader();
}, /^Error: "name" argument is required for getHeader\(name\)$/);
assert.throws(() => {
res.removeHeader();
}, /^Error: "name" argument is required for removeHeader\(name\)$/);
res.setHeader('x-test-header', 'testing');
res.setHeader('X-TEST-HEADER2', 'testing');
+1 -1
View File
@@ -22,5 +22,5 @@ function testContext(repl) {
assert.strictEqual(context.global, context);
// ensure that the repl console instance does not have a setter
assert.throws(() => context.console = 'foo');
assert.throws(() => context.console = 'foo', TypeError);
}
@@ -14,7 +14,7 @@ console.error('thrown error');
script = new Script('throw new Error(\'test\');');
assert.throws(function() {
script.runInThisContext(script);
});
}, /^Error: test$/);
global.hello = 5;
script = new Script('hello = 2');