pick.spec.ts 794 B

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