summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js
blob: f5fde6fbad76347efc3924401afb0b7138faf713 (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
describe("function declarations in if statement clauses", () => {
    test("if clause", () => {
        if (true) function foo() {}
        if (false) function bar() {}
        expect(typeof foo).toBe("function");
        expect(typeof bar).toBe("undefined");
    });

    test("else clause", () => {
        if (false);
        else function foo() {}
        if (true);
        else function bar() {}
        expect(typeof foo).toBe("function");
        expect(typeof bar).toBe("undefined");
    });

    test("if and else clause", () => {
        if (true) function foo() {}
        else function bar() {}
        expect(typeof foo).toBe("function");
        expect(typeof bar).toBe("undefined");
    });

    test("syntax error in strict mode", () => {
        expect(`
            "use strict";
            if (true) function foo() {}
        `).not.toEval();
        expect(`
            "use strict";
            if (false);
            else function foo() {}
        `).not.toEval();
        expect(`
            "use strict";
            if (false) function foo() {}
            else function bar() {}
        `).not.toEval();
    });
});