Skip to main content
Module

x/rambda/pick.spec.js

Faster and smaller alternative to Ramda
Go to Latest
File
import { pick } from './pick'
const obj = { a : 1, b : 2, c : 3,}
test('props to pick is a string', () => { const result = pick('a,c', obj) const resultCurry = pick('a,c')(obj) const expectedResult = { a : 1, c : 3, }
expect(result).toEqual(expectedResult) expect(resultCurry).toEqual(expectedResult)})
test('when prop is missing', () => { const result = pick('a,d,f', obj) expect(result).toEqual({ a : 1 })})
test('props to pick is an array', () => { expect(pick([ 'a', 'c' ])({ a : 'foo', b : 'bar', c : 'baz', })).toEqual({ a : 'foo', c : 'baz', })
expect(pick([ 'a', 'd', 'e', 'f' ])({ a : 'foo', b : 'bar', c : 'baz', })).toEqual({ a : 'foo' })
expect(pick('a,d,e,f')(null)).toEqual(undefined)})
test('works with list as input and number as props - props to pick is an array', () => { const result = pick([ 1, 2 ], [ 'a', 'b', 'c', 'd' ]) expect(result).toEqual({ 1 : 'b', 2 : 'c', })})
test('works with list as input and number as props - props to pick is a string', () => { const result = pick('1,2', [ 'a', 'b', 'c', 'd' ]) expect(result).toEqual({ 1 : 'b', 2 : 'c', })})
test('with symbol', () => { const symbolProp = Symbol('s') expect(pick([ symbolProp ], { [ symbolProp ] : 'a' })).toMatchInlineSnapshot(` Object { Symbol(s): "a", } `)})