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

Function test

test/object/has_own_property.js:7–34  ·  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 testHasOwnProperty (nativeHasOwnProperty) {
9 const obj = { one: 1 };
10
11 Object.defineProperty(obj, 'two', { value: 2 });
12
13 assert.strictEqual(nativeHasOwnProperty(obj, 'one'), true);
14 assert.strictEqual(nativeHasOwnProperty(obj, 'two'), true);
15 assert.strictEqual('toString' in obj, true);
16 assert.strictEqual(nativeHasOwnProperty(obj, 'toString'), false);
17 }
18
19 function testShouldThrowErrorIfKeyIsInvalid (nativeHasOwnProperty) {
20 assert.throws(() => {
21 nativeHasOwnProperty(undefined, 'test');
22 }, /Cannot convert undefined or null to object/);
23 }
24
25 testHasOwnProperty(binding.object.hasOwnPropertyWithNapiValue);
26 testHasOwnProperty(binding.object.hasOwnPropertyWithNapiWrapperValue);
27 testHasOwnProperty(binding.object.hasOwnPropertyWithCStyleString);
28 testHasOwnProperty(binding.object.hasOwnPropertyWithCppStyleString);
29
30 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithNapiValue);
31 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithNapiWrapperValue);
32 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithCStyleString);
33 testShouldThrowErrorIfKeyIsInvalid(binding.object.hasOwnPropertyWithCppStyleString);
34}

Callers

nothing calls this directly

Calls 2

testHasOwnPropertyFunction · 0.85

Tested by

no test coverage detected