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

Function test

test/object/has_property.js:7–37  ·  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 testHasProperty (nativeHasProperty) {
9 const obj = { one: 1 };
10
11 Object.defineProperty(obj, 'two', { value: 2 });
12
13 assert.strictEqual(nativeHasProperty(obj, 'one'), true);
14 assert.strictEqual(nativeHasProperty(obj, 'two'), true);
15 assert.strictEqual('toString' in obj, true);
16 assert.strictEqual(nativeHasProperty(obj, 'toString'), true);
17 }
18
19 function testShouldThrowErrorIfKeyIsInvalid (nativeHasProperty) {
20 assert.throws(() => {
21 nativeHasProperty(undefined, 'test');
22 }, /Cannot convert undefined or null to object/);
23 }
24
25 const objectWithInt32Key = { 12: 101 };
26 assert.strictEqual(binding.object.hasPropertyWithUint32(objectWithInt32Key, 12), true);
27
28 testHasProperty(binding.object.hasPropertyWithNapiValue);
29 testHasProperty(binding.object.hasPropertyWithNapiWrapperValue);
30 testHasProperty(binding.object.hasPropertyWithCStyleString);
31 testHasProperty(binding.object.hasPropertyWithCppStyleString);
32
33 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiValue);
34 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithNapiWrapperValue);
35 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCStyleString);
36 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasPropertyWithCppStyleString);
37}

Callers

nothing calls this directly

Calls 2

testHasPropertyFunction · 0.85

Tested by

no test coverage detected