/
set_property.js
31 lines (25 loc) · 1.21 KB
/
set_property.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'use strict';
const assert = require('assert');
module.exports = require('../common').runTest(test);
function test (binding) {
function testSetProperty (nativeSetProperty, key = 'test') {
const obj = {};
assert.strictEqual(nativeSetProperty(obj, key, 1), true);
assert.strictEqual(obj[key], 1);
}
function testShouldThrowErrorIfKeyIsInvalid (nativeSetProperty) {
assert.throws(() => {
nativeSetProperty(undefined, 'test', 1);
}, /Cannot convert undefined or null to object/);
}
testSetProperty(binding.object.setPropertyWithNapiValue);
testSetProperty(binding.object.setPropertyWithNapiWrapperValue);
testSetProperty(binding.object.setPropertyWithCStyleString);
testSetProperty(binding.object.setPropertyWithCppStyleString);
testSetProperty(binding.object.setPropertyWithUint32, 12);
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiValue);
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiWrapperValue);
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCStyleString);
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCppStyleString);
testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithUint32);
}