UNPKG

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