summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests/builtins/JSON/JSON.stringify-space.js
blob: 75873367bf6683689af2bed625efba4dc1e445f8 (plain)
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
test("basic functionality", () => {
    let o = {
        foo: 1,
        bar: "baz",
        qux: {
            get x() {
                return 10;
            },
            y() {
                return 20;
            },
            arr: [1, 2, 3],
        },
    };

    let string = JSON.stringify(o, null, 4);
    let expected = `{
    "foo": 1,
    "bar": "baz",
    "qux": {
        "x": 10,
        "arr": [
            1,
            2,
            3
        ]
    }
}`;

    expect(string).toBe(expected);

    string = JSON.stringify(o, null, "abcd");
    expected = `{
abcd"foo": 1,
abcd"bar": "baz",
abcd"qux": {
abcdabcd"x": 10,
abcdabcd"arr": [
abcdabcdabcd1,
abcdabcdabcd2,
abcdabcdabcd3
abcdabcd]
abcd}
}`;

    expect(string).toBe(expected);
});