(binding)
| 5 | module.exports = require('../common').runTest(test); |
| 6 | |
| 7 | function test (binding) { |
| 8 | function testGetProperty (nativeGetProperty) { |
| 9 | const obj = { test: 1 }; |
| 10 | assert.strictEqual(nativeGetProperty(obj, 'test'), 1); |
| 11 | } |
| 12 | |
| 13 | function testShouldReturnUndefinedIfKeyIsNotPresent (nativeGetProperty) { |
| 14 | const obj = { }; |
| 15 | assert.strictEqual(nativeGetProperty(obj, 'test'), undefined); |
| 16 | } |
| 17 | |
| 18 | function testShouldThrowErrorIfKeyIsInvalid (nativeGetProperty) { |
| 19 | assert.throws(() => { |
| 20 | nativeGetProperty(undefined, 'test'); |
| 21 | }, /Cannot convert undefined or null to object/); |
| 22 | } |
| 23 | |
| 24 | const testObject = { 42: 100 }; |
| 25 | const property = binding.object.getPropertyWithUint32(testObject, 42); |
| 26 | assert.strictEqual(property, 100); |
| 27 | |
| 28 | const nativeFunctions = [ |
| 29 | binding.object.getPropertyWithNapiValue, |
| 30 | binding.object.getPropertyWithNapiWrapperValue, |
| 31 | binding.object.getPropertyWithCStyleString, |
| 32 | binding.object.getPropertyWithCppStyleString |
| 33 | ]; |
| 34 | |
| 35 | nativeFunctions.forEach((nativeFunction) => { |
| 36 | testGetProperty(nativeFunction); |
| 37 | testShouldReturnUndefinedIfKeyIsNotPresent(nativeFunction); |
| 38 | testShouldThrowErrorIfKeyIsInvalid(nativeFunction); |
| 39 | }); |
| 40 | } |
nothing calls this directly
no test coverage detected