UNPKG

1.52 kBJavaScriptView Raw
1import { expectType } from "ts-expect";
2import { flatten } from "./index";
3describe("flatten", function () {
4 it("should flatten an array", function () {
5 var result = flatten([1, [2, [3, [4, [5]]], 6, [[7], 8], 9], 10]);
6 expectType(result);
7 expect(result).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
8 });
9 it("should work with array-like", function () {
10 var result = flatten("test");
11 expectType(result);
12 expect(result).toStrictEqual(["t", "e", "s", "t"]);
13 });
14 it("should work with readonly array", function () {
15 var input = [1, [2, [3, [4]]]];
16 var result = flatten(input);
17 expectType(result);
18 expect(result).toStrictEqual([1, 2, 3, 4]);
19 });
20 it("should work with arguments", function () {
21 var input = (function () {
22 return arguments;
23 })();
24 var result = flatten(input);
25 expectType(result);
26 expect(result).toStrictEqual([]);
27 });
28 it("should work with mixed types", function () {
29 var fn = function (x) { return x; };
30 var input = [1, ["test", [fn, [true]]]];
31 var result = flatten(input);
32 expectType(result);
33 expect(result).toStrictEqual([1, "test", fn, true]);
34 });
35 it("should work with tuples", function () {
36 var input = [1, [1, 2], [3]];
37 var result = flatten(input);
38 expectType(result);
39 expect(result).toStrictEqual([1, 1, 2, 3]);
40 });
41});
42//# sourceMappingURL=index.spec.js.map
\No newline at end of file