From f8c2585fe0de078e72fda13b5675f38d12b4b12e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Zasso?= Date: Fri, 7 Apr 2017 16:15:46 +0200 Subject: [PATCH] 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. Backport-PR-URL: https://github.com/nodejs/node/pull/19447 PR-URL: https://github.com/nodejs/node/pull/12270 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott --- test/addons-napi/test_constructor/test.js | 6 +++--- test/addons-napi/test_properties/test.js | 6 +++--- test/parallel/test-assert.js | 22 +++++++++++++--------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/test/addons-napi/test_constructor/test.js b/test/addons-napi/test_constructor/test.js index b1762c2253b99a..92440bf49e74c1 100644 --- a/test/addons-napi/test_constructor/test.js +++ b/test/addons-napi/test_constructor/test.js @@ -13,7 +13,7 @@ assert.strictEqual(test_object.readwriteValue, 1); test_object.readwriteValue = 2; assert.strictEqual(test_object.readwriteValue, 2); -assert.throws(() => { test_object.readonlyValue = 3; }); +assert.throws(() => { test_object.readonlyValue = 3; }, TypeError); assert.ok(test_object.hiddenValue); @@ -35,8 +35,8 @@ assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0); test_object.readwriteAccessor1 = 1; assert.strictEqual(test_object.readwriteAccessor1, 1); assert.strictEqual(test_object.readonlyAccessor1, 1); -assert.throws(() => { test_object.readonlyAccessor1 = 3; }); +assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError); test_object.readwriteAccessor2 = 2; assert.strictEqual(test_object.readwriteAccessor2, 2); assert.strictEqual(test_object.readonlyAccessor2, 2); -assert.throws(() => { test_object.readonlyAccessor2 = 3; }); +assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError); diff --git a/test/addons-napi/test_properties/test.js b/test/addons-napi/test_properties/test.js index fb0c19ceedb086..868c603879f1a2 100644 --- a/test/addons-napi/test_properties/test.js +++ b/test/addons-napi/test_properties/test.js @@ -12,7 +12,7 @@ assert.strictEqual(test_object.readwriteValue, 1); test_object.readwriteValue = 2; assert.strictEqual(test_object.readwriteValue, 2); -assert.throws(() => { test_object.readonlyValue = 3; }); +assert.throws(() => { test_object.readonlyValue = 3; }, TypeError); assert.ok(test_object.hiddenValue); @@ -34,8 +34,8 @@ assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0); test_object.readwriteAccessor1 = 1; assert.strictEqual(test_object.readwriteAccessor1, 1); assert.strictEqual(test_object.readonlyAccessor1, 1); -assert.throws(() => { test_object.readonlyAccessor1 = 3; }); +assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError); test_object.readwriteAccessor2 = 2; assert.strictEqual(test_object.readwriteAccessor2, 2); assert.strictEqual(test_object.readonlyAccessor2, 2); -assert.throws(() => { test_object.readonlyAccessor2 = 3; }); +assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError); diff --git a/test/parallel/test-assert.js b/test/parallel/test-assert.js index 55376328b026f2..9b82c3ff4cccf9 100644 --- a/test/parallel/test-assert.js +++ b/test/parallel/test-assert.js @@ -522,15 +522,19 @@ testAssertionMessage({a: undefined, b: null}, '{ a: undefined, b: null }'); testAssertionMessage({a: NaN, b: Infinity, c: -Infinity}, '{ a: NaN, b: Infinity, c: -Infinity }'); -// https://github.com/nodejs/node-v0.x-archive/issues/2893 -try { - // eslint-disable-next-line no-restricted-syntax - assert.throws(function() { - assert.ifError(null); - }); -} catch (e) { - threw = true; - assert.strictEqual(e.message, 'Missing expected exception..'); +// #2893 +{ + let threw = false; + try { + // eslint-disable-next-line no-restricted-syntax + assert.throws(function() { + assert.ifError(null); + }); + } catch (e) { + threw = true; + assert.strictEqual(e.message, 'Missing expected exception..'); + } + assert.ok(threw); } assert.ok(threw);