You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
727 B
39 lines
727 B
import { get } from '../src'
|
|
|
|
test('returns a deeply nested value', () => {
|
|
const a = get(
|
|
{
|
|
colors: {
|
|
blue: ['#0cf', '#0be', '#09d', '#07c'],
|
|
},
|
|
},
|
|
'colors.blue.3'
|
|
)
|
|
expect(a).toBe('#07c')
|
|
})
|
|
|
|
test('supports fallback values', () => {
|
|
const a = get({}, 'hi', 'nope')
|
|
expect(a).toBe('nope')
|
|
})
|
|
|
|
test('handles number values', () => {
|
|
const a = get([1, 2, 3], 0)
|
|
expect(a).toBe(1)
|
|
})
|
|
|
|
test('handles undefined values', () => {
|
|
const a = get({}, undefined)
|
|
expect(a).toBe(undefined)
|
|
})
|
|
|
|
test('handles null values', () => {
|
|
const a = get({}, null)
|
|
expect(a).toBe(undefined)
|
|
})
|
|
|
|
test('returns 0 index items', () => {
|
|
const a = get([ 'a', 'b', 'c' ], 0)
|
|
expect(a).toBe('a')
|
|
})
|