deno.land / x / rambda@v9.1.1 / source / path.spec.js

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { path } from './path.js'
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' } } })).toBe('yes')})
test('path', () => { expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : { baz : 'yes' } } })).toBe('yes')
expect(path([ 'foo', 'bar', 'baz' ])(null)).toBeUndefined()
expect(path([ 'foo', 'bar', 'baz' ])({ foo : { bar : 'baz' } })).toBeUndefined()})
test('null is not a valid path', () => { expect(path('audio_tracks', { a : 1, audio_tracks : null, })).toBeUndefined()})
rambda

Version Info

Tagged at
2 months ago