forked from czabaj/stringify-replacers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.ts
More file actions
64 lines (57 loc) · 1.36 KB
/
test.ts
File metadata and controls
64 lines (57 loc) · 1.36 KB
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
import { assertEquals } from "https://deno.land/std@0.80.0/testing/asserts.ts";
import { stringify } from "./mod.ts";
Deno.test(`should print only chosen maxDepth during serializing`, () => {
const deepObject = {
enten: {
tyky: {
dva: {
spaliky: {
cert: {
vyletel: {
z: `elektriky`,
},
},
},
},
},
},
};
assertEquals(
stringify(deepObject, { maxDepth: 3 }),
`{"enten":{"tyky":{"dva":"[object Object]"}}}`,
);
});
Deno.test(`should handle serialization of Map objects with respect to maxDepts`, () => {
const deepObjectWithMap = {
enten: {
tyky: new Map([
[
"dva",
new Map([
[
"spaliky",
{
cert: {
vyletel: {
z: `elektriky`,
},
},
},
],
]),
],
]),
},
};
assertEquals(
stringify(deepObjectWithMap, { maxDepth: 3, supportMap: true }),
`{"enten":{"tyky":{"dva":"[object Object]"}}}`,
);
});
Deno.test(`should print first level when "maxDepth" is 1`, () => {
const object = { foo: 1, bar: { ara: "rat" } };
assertEquals(
stringify(object, { maxDepth: 1 }),
`{"foo":1,"bar":"[object Object]"}`,
);
});