aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/util/assign-keys.spec.ts
blob: 43afe38d306001528f44f0e7ee6d3ffcc47dc0cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { assignKeys } from './assign-keys';

describe('util/assign-keys', () => {
  it('should assign values from right to left for specified keys', () => {
    type Left = {
      foo: number | string;
      bar: number | boolean;
      baz?: number;
    };
    const left: Left = {
      foo: 'foo',
      bar: false,
      baz: 42,
    };

    type Right = {
      foo?: number;
      bar?: number;
      baz?: number;
    };
    const right: Right = {
      foo: 1,
      bar: 2,
      baz: 3,
    };

    const result = assignKeys(left, right, ['foo', 'bar']);
    expect(result).toEqual({
      foo: 1,
      bar: 2,
      baz: 42,
    });
    expect(result).toBe(left);
  });
});