(binding)
| 5 | module.exports = require('../common').runTest(test); |
| 6 | |
| 7 | function 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 | } |
nothing calls this directly
no test coverage detected