-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathomitInvalid.test.ts
77 lines (69 loc) · 2.22 KB
/
omitInvalid.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import * as assert from "node:assert";
import { omitInvalid } from "./index.ts";
describe("omitInvalid", () => {
it("should omit properties of void values from the object", () => {
let obj = {
name: "Ayon Lee",
nil: void 0,
nil2: null,
nil3: NaN,
date: new Date("invalid"),
};
let arr = [void 0, 1, null, 2, NaN, 3];
assert.deepStrictEqual(omitInvalid(obj), { name: "Ayon Lee" });
assert.deepStrictEqual(omitInvalid(arr), [1, 2, 3]);
});
it("should omit properties of void values deeply from the object", () => {
let obj = {
name: "Ayon Lee",
nil: void 0,
child: {
name: "Luna",
nil: null
},
child2: {
nil: NaN,
date: new Date("invalid"),
}
};
let arr = [void 0, [null, [NaN, "Ayon Lee"]]];
assert.deepStrictEqual(omitInvalid(obj, true), {
name: "Ayon Lee",
child: { name: "Luna" },
child2: {}
});
assert.deepStrictEqual(omitInvalid(arr, true), [[["Ayon Lee"]]]);
});
it("should omit properties of void values deeply from the object", () => {
let obj = {
name: "Ayon Lee",
nil: void 0,
child: {
nil: null
},
child2: [NaN, new Date("invalid")]
};
let arr = [void 0, [null, [NaN]]];
assert.deepStrictEqual(omitInvalid(obj, true, true), {
name: "Ayon Lee"
});
assert.deepStrictEqual(omitInvalid(arr, true, true), []);
});
it("should omit properties of empty strings deeply from the object", () => {
let obj = {
name: "Ayon Lee",
nil: void 0,
child: {
nil: null,
str: "",
date: new Date("invalid"),
},
child2: [NaN]
};
let arr = [void 0, [null, [NaN, ""]]];
assert.deepStrictEqual(omitInvalid(obj, true, true, true), {
name: "Ayon Lee"
});
assert.deepStrictEqual(omitInvalid(arr, true, true, true), []);
});
});