-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflat.test.ts
More file actions
27 lines (21 loc) · 899 Bytes
/
flat.test.ts
File metadata and controls
27 lines (21 loc) · 899 Bytes
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
import { flat } from "../lib";
describe("flat", () => {
test("flattens", () => {
expect(flat([0, [1, 2], [3, 4], [5]])).toEqual([0, 1, 2, 3, 4, 5]);
});
test("flattens 2 deep", () => {
expect(flat([0, [1, 2, [3, 4]], [5]])).toEqual([0, 1, 2, 3, 4, 5]);
});
test("flattens 3 deep", () => {
expect(flat([0, [1, 2, [3, 4, [5]]]])).toEqual([0, 1, 2, 3, 4, 5]);
});
test("no side-effects", () => {
const origin = [{ a: 0 }, [{ a: 1 }, { a: 2 }, [{ a: 3 }, { a: 4 }, [{ a: 5 }]]]];
const flattened = flat(origin);
expect(flattened).toEqual([{ a: 0 }, { a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }]);
const n = flattened[0] as { a: number };
n.a += 1;
expect(origin).toEqual([{ a: 0 }, [{ a: 1 }, { a: 2 }, [{ a: 3 }, { a: 4 }, [{ a: 5 }]]]]);
expect(flattened).toEqual([{ a: 1 }, { a: 1 }, { a: 2 }, { a: 3 }, { a: 4 }, { a: 5 }]);
});
});