summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Tests/HTML/document.body.js
blob: 71cf6f37deace02f6abb52c43e744c61b6b61010 (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
48
49
50
51
52
53
54
55
loadPage("file:///res/html/misc/blank.html");

afterInitialPageLoad(() => {
    test("Basic functionality", () => {
        expect(document.body).not.toBeNull();
        // FIXME: Add this in once HTMLBodyElement's constructor is implemented.
        //expect(document.body).toBeInstanceOf(HTMLBodyElement);
        expect(document.body.nodeName).toBe("BODY");
    });

    // FIXME: Add this in once set_body is fully implemented.
    test.skip("Setting body to a new body element", () => {
        // Add something to body to see if it's gone afterwards
        const p = document.createElement("p");
        document.body.appendChild(p);

        expect(document.body.firstChild).toBe(p);

        const newBody = document.createElement("body");
        document.body = newBody;

        expect(document.body).not.toBeNull();
        expect(document.body.nodeName).toBe("BODY");

        // FIXME: Add this in once HTMLBodyElement's constructor is implemented.
        //expect(document.body).toBeInstanceOf(HTMLBodyElement);

        expect(document.body.firstChild).toBeNull();
    });

    // FIXME: Add this in once set_body is fully implemented.
    test.skip("Setting body to a new frameset element", () => {
        const newFrameSet = document.createElement("frameset");
        document.body = newFrameSet;

        expect(document.body).not.toBeNull();
        expect(document.body.nodeName).toBe("FRAMESET");

        // FIXME: Add this in once HTMLFrameSetElement's constructor is implemented.
        //expect(document.body).toBeInstanceOf(HTMLFrameSetElement);
    });

    // FIXME: Add this in once set_body is fully implemented.
    test.skip("Setting body to an element that isn't body/frameset", () => {
        expect(() => {
            document.body = document.createElement("div");
        }).toThrow(DOMException);
    });

    // FIXME: Add this in once removeChild is implemented.
    test.skip("Nullable", () => {
        document.documentElement.removeChild(document.body);
        expect(document.body).toBeNull();
    });
});