Skip to content

Commit f8c2585

Browse files
targosMylesBorins
authored andcommitted
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: #19447 PR-URL: #12270 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 6bf3d04 commit f8c2585

File tree

3 files changed

+19
-15
lines changed

3 files changed

+19
-15
lines changed

test/addons-napi/test_constructor/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ assert.strictEqual(test_object.readwriteValue, 1);
1313
test_object.readwriteValue = 2;
1414
assert.strictEqual(test_object.readwriteValue, 2);
1515

16-
assert.throws(() => { test_object.readonlyValue = 3; });
16+
assert.throws(() => { test_object.readonlyValue = 3; }, TypeError);
1717

1818
assert.ok(test_object.hiddenValue);
1919

@@ -35,8 +35,8 @@ assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
3535
test_object.readwriteAccessor1 = 1;
3636
assert.strictEqual(test_object.readwriteAccessor1, 1);
3737
assert.strictEqual(test_object.readonlyAccessor1, 1);
38-
assert.throws(() => { test_object.readonlyAccessor1 = 3; });
38+
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError);
3939
test_object.readwriteAccessor2 = 2;
4040
assert.strictEqual(test_object.readwriteAccessor2, 2);
4141
assert.strictEqual(test_object.readonlyAccessor2, 2);
42-
assert.throws(() => { test_object.readonlyAccessor2 = 3; });
42+
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError);

test/addons-napi/test_properties/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ assert.strictEqual(test_object.readwriteValue, 1);
1212
test_object.readwriteValue = 2;
1313
assert.strictEqual(test_object.readwriteValue, 2);
1414

15-
assert.throws(() => { test_object.readonlyValue = 3; });
15+
assert.throws(() => { test_object.readonlyValue = 3; }, TypeError);
1616

1717
assert.ok(test_object.hiddenValue);
1818

@@ -34,8 +34,8 @@ assert.ok(propertyNames.indexOf('readonlyAccessor2') < 0);
3434
test_object.readwriteAccessor1 = 1;
3535
assert.strictEqual(test_object.readwriteAccessor1, 1);
3636
assert.strictEqual(test_object.readonlyAccessor1, 1);
37-
assert.throws(() => { test_object.readonlyAccessor1 = 3; });
37+
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError);
3838
test_object.readwriteAccessor2 = 2;
3939
assert.strictEqual(test_object.readwriteAccessor2, 2);
4040
assert.strictEqual(test_object.readonlyAccessor2, 2);
41-
assert.throws(() => { test_object.readonlyAccessor2 = 3; });
41+
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError);

test/parallel/test-assert.js

+13-9
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,19 @@ testAssertionMessage({a: undefined, b: null}, '{ a: undefined, b: null }');
522522
testAssertionMessage({a: NaN, b: Infinity, c: -Infinity},
523523
'{ a: NaN, b: Infinity, c: -Infinity }');
524524

525-
// https://github.com/nodejs/node-v0.x-archive/issues/2893
526-
try {
527-
// eslint-disable-next-line no-restricted-syntax
528-
assert.throws(function() {
529-
assert.ifError(null);
530-
});
531-
} catch (e) {
532-
threw = true;
533-
assert.strictEqual(e.message, 'Missing expected exception..');
525+
// #2893
526+
{
527+
let threw = false;
528+
try {
529+
// eslint-disable-next-line no-restricted-syntax
530+
assert.throws(function() {
531+
assert.ifError(null);
532+
});
533+
} catch (e) {
534+
threw = true;
535+
assert.strictEqual(e.message, 'Missing expected exception..');
536+
}
537+
assert.ok(threw);
534538
}
535539
assert.ok(threw);
536540

0 commit comments

Comments
 (0)