diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index ca25c9965d0640..74ef705f13305f 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -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); }); diff --git a/test/parallel/test-buffer.js b/test/parallel/test-buffer.js index 805c8b9e7ac347..a2fdab55b772a8 100644 --- a/test/parallel/test-buffer.js +++ b/test/parallel/test-buffer.js @@ -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.'); diff --git a/test/parallel/test-http-mutable-headers.js b/test/parallel/test-http-mutable-headers.js index 8f9d597efbec92..2a4b0dc6c1c99b 100644 --- a/test/parallel/test-http-mutable-headers.js +++ b/test/parallel/test-http-mutable-headers.js @@ -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'); diff --git a/test/parallel/test-repl-context.js b/test/parallel/test-repl-context.js index 2287a247d81bb2..a2f04214311c13 100644 --- a/test/parallel/test-repl-context.js +++ b/test/parallel/test-repl-context.js @@ -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); } diff --git a/test/parallel/test-vm-new-script-this-context.js b/test/parallel/test-vm-new-script-this-context.js index 3df5dc1b5020d5..62aecfed28af4f 100644 --- a/test/parallel/test-vm-new-script-this-context.js +++ b/test/parallel/test-vm-new-script-this-context.js @@ -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');