Skip to content

Commit

Permalink
test: add second argument to assert.throws
Browse files Browse the repository at this point in the history
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: #19447
PR-URL: #12270
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
targos authored and MylesBorins committed Apr 16, 2018
1 parent 6bf3d04 commit f8c2585
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
6 changes: 3 additions & 3 deletions test/addons-napi/test_constructor/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
6 changes: 3 additions & 3 deletions test/addons-napi/test_properties/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
22 changes: 13 additions & 9 deletions test/parallel/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit f8c2585

Please sign in to comment.