-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathto-array.test.ts
55 lines (49 loc) · 973 Bytes
/
to-array.test.ts
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
import { inspect } from 'node:util';
import { toArray } from './to-array.js';
const fn = (): undefined => undefined;
const cases: [unknown, unknown][] = [
[null, [null]],
[
[null, null],
[null, null],
],
[undefined, [undefined]],
[
[undefined, undefined],
[undefined, undefined],
],
[1, [1]],
[
[1, 2],
[1, 2],
],
['abc', ['abc']],
[
['abc', 'def'],
['abc', 'def'],
],
[true, [true]],
[
[true, false],
[true, false],
],
[fn, [fn]],
[
[fn, fn],
[fn, fn],
],
[{ 0: 'abc', 1: 'def', length: 2 }, ['abc', 'def']],
[new Set([1, 2, 3]), [1, 2, 3]],
];
describe('toArray', () => {
cases.forEach(([value, expected]) => {
test(inspect(value), () => {
expect(toArray(value)).toEqual(expected);
});
});
test('mixed types', () => {
const value = 1 as string[] | number;
const array: (number | string)[] = toArray(value);
expect(array).toEqual([1]);
});
});