Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/node-red/node_modules/object-get/test/ drwxr-xr-x | |
| Viewing file: Select action/file-type: 'use strict'
var test = require('tape')
var objectGet = require('../')
test('.get(object, expression)', function (t) {
var fixture = {
one: 1,
two: {
three: 3,
four: {
five: 5
}
}
}
t.strictEqual(objectGet(fixture, 'one'), 1)
t.strictEqual(objectGet(fixture, 'two.three'), 3)
t.strictEqual(objectGet(fixture, 'two.four.five'), 5)
t.deepEqual(objectGet(fixture, 'two'), {
three: 3,
four: {
five: 5
}
})
t.deepEqual(objectGet(fixture, 'two.four'), {
five: 5
})
t.strictEqual(objectGet(fixture, 'ksfjglfshg'), undefined)
t.end()
})
test('arrays in expression', function (t) {
var element = {
children: [
{ one : 1 },
{ two: 2, children: [
{ three: 3 }
]}
]
}
t.strictEqual(objectGet(element, 'children[0].one'), 1)
t.strictEqual(objectGet(element, 'children[1].children[0].three'), 3)
t.strictEqual(objectGet(element, 'otherChildren[0].four'), undefined)
t.strictEqual(objectGet(element, 'children[1].otherChildren[0].five'), undefined)
t.end()
})
test('bad args', function (t) {
t.throws(function () {
objectGet({ one: 1 })
})
t.throws(function () {
objectGet({ one: 1 }, undefined)
})
t.throws(function () {
objectGet(null, 'one')
})
t.throws(function () {
objectGet(undefined, null)
})
t.end()
})
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0047 ]-- |