generated from sapphiredev/sapphire-template
-
-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathobjectEntries.test.ts
More file actions
65 lines (53 loc) · 1.66 KB
/
objectEntries.test.ts
File metadata and controls
65 lines (53 loc) · 1.66 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { objectEntries } from '../src';
describe('objectEntries', () => {
test('GIVEN basic readonly THEN returns expected', () => {
const source = { a: 'Hello', b: 420 } as const;
const expected = [
['a', 'Hello'],
['b', 420]
];
expect<['a' | 'b', 'Hello' | 420][]>(objectEntries(source)).toEqual(expected);
});
test('GIVEN deep readonly THEN returns expected', () => {
const source = { a: 'Hello', b: 420, deep: { i: [] } } as const;
const expected = [
['a', 'Hello'],
['b', 420],
['deep', { i: [] }]
];
expect<['a' | 'b' | 'deep', 'Hello' | 420 | { i: readonly [] }][]>(objectEntries(source)).toEqual(expected);
});
test('GIVEN array readonly THEN returns expected', () => {
const source = ['Hello', 420] as const;
const expected = [
['0', 'Hello'],
['1', 420]
];
expect<[`${number}`, 'Hello' | 420][]>(objectEntries(source)).toEqual(expected);
});
test('GIVEN basic THEN returns expected', () => {
const source = { a: 'Hello', b: 420 };
const expected = [
['a', 'Hello'],
['b', 420]
];
expect<['a' | 'b', string | number][]>(objectEntries(source)).toEqual(expected);
});
test('GIVEN deep THEN returns expected', () => {
const source = { a: 'Hello', b: 420, deep: { i: [] } };
const expected = [
['a', 'Hello'],
['b', 420],
['deep', { i: [] }]
];
expect<['a' | 'b' | 'deep', string | number | { i: never[] }][]>(objectEntries(source)).toEqual(expected);
});
test('GIVEN array THEN returns expected', () => {
const source = ['Hello', 420];
const expected = [
['0', 'Hello'],
['1', 420]
];
expect<[`${number}`, string | number][]>(objectEntries(source)).toEqual(expected);
});
});