pick.spec.ts 746 B

1234567891011121314151617181920212223242526272829303132
  1. import { pick } from './pick';
  2. describe('pick()', () => {
  3. it('picks specified properties', () => {
  4. const input = {
  5. foo: 1,
  6. bar: 2,
  7. baz: [1, 2, 3],
  8. };
  9. const result = pick(input, ['foo', 'baz']);
  10. expect(result).toEqual({
  11. foo: 1,
  12. baz: [1, 2, 3],
  13. });
  14. });
  15. it('partially applies the pick when signle argument is array', () => {
  16. const input = {
  17. foo: 1,
  18. bar: 2,
  19. baz: [1, 2, 3],
  20. };
  21. const result = pick(['foo', 'baz']);
  22. expect(typeof result).toBe('function');
  23. expect(result(input)).toEqual({
  24. foo: 1,
  25. baz: [1, 2, 3],
  26. });
  27. });
  28. });