ray-template/__test__/basic/pick.spec.ts
2024-03-23 11:25:28 +08:00

26 lines
646 B
TypeScript

import { pick } from '../../src/utils/basic'
describe('pick', () => {
it('should pick keys from object', () => {
const obj = { a: 1, b: 2, c: 3 }
const result = pick(obj, 'a', 'c')
expect(result).toEqual({ a: 1, c: 3 })
})
it('should pick keys from the array argument', () => {
const obj = { a: 1, b: 2, c: 3 }
const result = pick(obj, ['a', 'c'])
expect(result).toEqual({ a: 1, c: 3 })
})
it('an empty object should be returned if null or undefined is passed', () => {
const result1 = pick(null)
const result2 = pick(void 0)
expect(result1).toEqual({})
expect(result2).toEqual({})
})
})