MCPcopy Create free account
hub / github.com/nodejs/node-addon-api / test

Function test

test/object/set_property.js:7–30  ·  view source on GitHub ↗
(binding)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 2

testSetPropertyFunction · 0.85

Tested by

no test coverage detected