diff options
Diffstat (limited to 'Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js b/Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js new file mode 100644 index 0000000000..583585ebe5 --- /dev/null +++ b/Userland/Libraries/LibJS/Tests/if-statement-function-declaration.js @@ -0,0 +1,41 @@ +describe("function declarations in if statement clauses", () => { + test("if clause", () => { + if (true) function foo() {} + if (false) function bar() {} + expect(typeof globalThis.foo).toBe("function"); + expect(typeof globalThis.bar).toBe("undefined"); + }); + + test("else clause", () => { + if (false); + else function foo() {} + if (true); + else function bar() {} + expect(typeof globalThis.foo).toBe("function"); + expect(typeof globalThis.bar).toBe("undefined"); + }); + + test("if and else clause", () => { + if (true) function foo() {} + else function bar() {} + expect(typeof globalThis.foo).toBe("function"); + expect(typeof globalThis.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(); + }); +}); |