test: use regular expressions in throw assertions

Test errors thrown in addons-napi/test_constructor more specifically.

PR-URL: https://github.com/nodejs/node/pull/14318
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
This commit is contained in:
Vincent Xue 2017-07-17 11:58:38 +08:00 committed by Gabriel Schulhof
parent 314217f8fb
commit e6eb5c00da

View File

@ -13,7 +13,8 @@ assert.strictEqual(test_object.readwriteValue, 1);
test_object.readwriteValue = 2; test_object.readwriteValue = 2;
assert.strictEqual(test_object.readwriteValue, 2); assert.strictEqual(test_object.readwriteValue, 2);
assert.throws(() => { test_object.readonlyValue = 3; }, TypeError); assert.throws(() => { test_object.readonlyValue = 3; },
/^TypeError: Cannot assign to read only property 'readonlyValue' of object '#<MyObject>'$/);
assert.ok(test_object.hiddenValue); assert.ok(test_object.hiddenValue);
@ -35,11 +36,13 @@ assert.ok(!propertyNames.includes('readonlyAccessor2'));
test_object.readwriteAccessor1 = 1; test_object.readwriteAccessor1 = 1;
assert.strictEqual(test_object.readwriteAccessor1, 1); assert.strictEqual(test_object.readwriteAccessor1, 1);
assert.strictEqual(test_object.readonlyAccessor1, 1); assert.strictEqual(test_object.readonlyAccessor1, 1);
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError); assert.throws(() => { test_object.readonlyAccessor1 = 3; },
/^TypeError: Cannot assign to read only property 'readonlyAccessor1' of object '#<MyObject>'$/);
test_object.readwriteAccessor2 = 2; test_object.readwriteAccessor2 = 2;
assert.strictEqual(test_object.readwriteAccessor2, 2); assert.strictEqual(test_object.readwriteAccessor2, 2);
assert.strictEqual(test_object.readonlyAccessor2, 2); assert.strictEqual(test_object.readonlyAccessor2, 2);
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError); assert.throws(() => { test_object.readonlyAccessor2 = 3; },
/^TypeError: Cannot assign to read only property 'readonlyAccessor2' of object '#<MyObject>'$/);
// validate that static properties are on the class as opposed // validate that static properties are on the class as opposed
// to the instance // to the instance