-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobj.test.ts
57 lines (50 loc) · 1.04 KB
/
obj.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
import { assert, assertEquals } from "./test_deps.ts";
import { camelizeKeys, matchObj, walkDeep } from "./obj.ts";
Deno.test("camelizeKeys", () => {
const obj = {
user_obj: {
name: "Andrew",
roles: ["editor", "manager"],
created_at: "2023-05-22T19:30:29",
},
meta_data: {
is_new: false,
accepted_tos: true,
},
};
// deno-lint-ignore no-explicit-any
const res: any = camelizeKeys(obj);
assert(res.userObj);
assert(res.userObj.createdAt);
assert(!res["user_obj"]);
});
Deno.test("walkDeep", () => {
const obj = {
foo: {
nested: {
field: "bar",
},
},
baz: {
oof: "foofoo",
},
};
let visits = 0;
walkDeep(obj, () => visits++);
assertEquals(visits, 5);
});
Deno.test("matchObj", () => {
const obj = {
foo: {
nested: {
field: "bar",
},
},
baz: {
oof: "foofoo",
},
};
assert(matchObj(obj, { foo: { nested: { field: "bar" } } }));
assert(!matchObj(obj, { foo: "bar" }));
assert(!matchObj({}, {}));
});