Skip to content

Commit

Permalink
test: changed error message validator
Browse files Browse the repository at this point in the history
Replaced TypeError with RegEx to match the exact error message in file
test/addons-napi/test_properties/test.js. The RegEx will check the
validity of the error being thrown.

PR-URL: #14443
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
pratik0509 authored and addaleax committed Jul 26, 2017
1 parent c9e494c commit 7849b52
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test/addons-napi/test_properties/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';
const common = require('../../common');
const assert = require('assert');
const readonlyErrorRE = /^TypeError: Cannot assign to read only property '.*' of object '#<Object>'$/;

// Testing api calls for defining properties
const test_object = require(`./build/${common.buildType}/test_properties`);
Expand All @@ -12,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; }, TypeError);
assert.throws(() => { test_object.readonlyValue = 3; }, readonlyErrorRE);

assert.ok(test_object.hiddenValue);

Expand Down Expand Up @@ -42,11 +43,11 @@ assert.strictEqual(symbolDescription, 'NameKeySymbol');
test_object.readwriteAccessor1 = 1;
assert.strictEqual(test_object.readwriteAccessor1, 1);
assert.strictEqual(test_object.readonlyAccessor1, 1);
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, TypeError);
assert.throws(() => { test_object.readonlyAccessor1 = 3; }, readonlyErrorRE);
test_object.readwriteAccessor2 = 2;
assert.strictEqual(test_object.readwriteAccessor2, 2);
assert.strictEqual(test_object.readonlyAccessor2, 2);
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, TypeError);
assert.throws(() => { test_object.readonlyAccessor2 = 3; }, readonlyErrorRE);

assert.strictEqual(test_object.hasNamedProperty(test_object, 'echo'), true);
assert.strictEqual(test_object.hasNamedProperty(test_object, 'hiddenValue'),
Expand Down

0 comments on commit 7849b52

Please sign in to comment.