Skip to main content
Module

x/rambda/path.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { path } from './path'
test('with array inside object', () => { const obj = { a : { b : [ 1, { c : 1 } ] } }
expect(path('a.b.1.c', obj)).toBe(1)})
test('works with undefined', () => { const obj = { a : { b : { c : 1 } } }
expect(path('a.b.c.d.f', obj)).toBeUndefined() expect(path('foo.babaz', undefined)).toBeUndefined() expect(path('foo.babaz')(undefined)).toBeUndefined()})
test('works with string instead of array', () => { expect(path('foo.bar.baz')({ foo : { bar : { baz : 'yes' } } })).toEqual('yes')})
test('path', () => { expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : { baz : 'yes' } } })).toEqual('yes')
expect(path([ 'foo', 'bar', 'baz' ])(null)).toBeUndefined()
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : 'baz' } })).toBeUndefined()})