@imjano/get_object_in_object
Version:
Through a dot-separated path (example: 'subObject.foo.bar') you can find an object inside another parent object.
20 lines (18 loc) • 628 B
text/typescript
import getObjectInObject from '../src/main'
describe('Given a path divided by dots (example: "foo.bar") you can find an object inside another parent object', () => {
const object = {
foo: {
bar: 'hello world',
},
}
const emptyObject = {}
const path = 'foo.bar'
it('must find the object inside the parent object through the given path', () => {
const result = getObjectInObject(object, path)
expect(result).toBe('hello world')
})
it('must not find any object since it is an empty object', () => {
const result = getObjectInObject(emptyObject, path)
expect(result).toBe(undefined)
})
})