Skip to content

Commit e6eb5c0

Browse files
vincentcnGabriel Schulhof
authored and
Gabriel Schulhof
committed
test: use regular expressions in throw assertions
Test errors thrown in addons-napi/test_constructor more specifically. PR-URL: #14318 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent 314217f commit e6eb5c0

File tree

1 file changed

+6
-3
lines changed
  • test/addons-napi/test_constructor

1 file changed

+6
-3
lines changed

test/addons-napi/test_constructor/test.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ 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; }, TypeError);
16+
assert.throws(() => { test_object.readonlyValue = 3; },
17+
/^TypeError: Cannot assign to read only property 'readonlyValue' of object '#<MyObject>'$/);
1718

1819
assert.ok(test_object.hiddenValue);
1920

@@ -35,11 +36,13 @@ assert.ok(!propertyNames.includes('readonlyAccessor2'));
3536
test_object.readwriteAccessor1 = 1;
3637
assert.strictEqual(test_object.readwriteAccessor1, 1);
3738
assert.strictEqual(test_object.readonlyAccessor1, 1);
38-
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError);
39+
assert.throws(() => { test_object.readonlyAccessor1 = 3; },
40+
/^TypeError: Cannot assign to read only property 'readonlyAccessor1' of object '#<MyObject>'$/);
3941
test_object.readwriteAccessor2 = 2;
4042
assert.strictEqual(test_object.readwriteAccessor2, 2);
4143
assert.strictEqual(test_object.readonlyAccessor2, 2);
42-
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError);
44+
assert.throws(() => { test_object.readonlyAccessor2 = 3; },
45+
/^TypeError: Cannot assign to read only property 'readonlyAccessor2' of object '#<MyObject>'$/);
4346

4447
// validate that static properties are on the class as opposed
4548
// to the instance

0 commit comments

Comments
 (0)