summaryrefslogtreecommitdiff
path: root/test/addons-napi/test_properties/test.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/addons-napi/test_properties/test.js')
-rw-r--r--test/addons-napi/test_properties/test.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/addons-napi/test_properties/test.js b/test/addons-napi/test_properties/test.js
new file mode 100644
index 0000000000..8e19903dcf
--- /dev/null
+++ b/test/addons-napi/test_properties/test.js
@@ -0,0 +1,27 @@
+'use strict';
+const common = require('../../common');
+const assert = require('assert');
+
+// Testing api calls for defining properties
+const test_object = require(`./build/${common.buildType}/test_properties`);
+
+assert.strictEqual(test_object.echo('hello'), 'hello');
+
+test_object.readwriteValue = 1;
+assert.strictEqual(test_object.readwriteValue, 1);
+test_object.readwriteValue = 2;
+assert.strictEqual(test_object.readwriteValue, 2);
+
+assert.throws(() => { test_object.readonlyValue = 3; });
+
+assert.ok(test_object.hiddenValue);
+
+// All properties except 'hiddenValue' should be enumerable.
+const propertyNames = [];
+for (const name in test_object) {
+ propertyNames.push(name);
+}
+assert.ok(propertyNames.indexOf('echo') >= 0);
+assert.ok(propertyNames.indexOf('readwriteValue') >= 0);
+assert.ok(propertyNames.indexOf('readonlyValue') >= 0);
+assert.ok(propertyNames.indexOf('hiddenValue') < 0);