if-statement-function-declaration.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. describe("function declarations in if statement clauses", () => {
  2. test("if clause", () => {
  3. if (true) function foo() {}
  4. if (false) function bar() {}
  5. expect(typeof foo).toBe("function");
  6. expect(typeof bar).toBe("undefined");
  7. });
  8. test("else clause", () => {
  9. if (false);
  10. else function foo() {}
  11. if (true);
  12. else function bar() {}
  13. expect(typeof foo).toBe("function");
  14. expect(typeof bar).toBe("undefined");
  15. });
  16. test("if and else clause", () => {
  17. if (true) function foo() {}
  18. else function bar() {}
  19. expect(typeof foo).toBe("function");
  20. expect(typeof bar).toBe("undefined");
  21. });
  22. test("syntax error in strict mode", () => {
  23. expect(`
  24. "use strict";
  25. if (true) function foo() {}
  26. `).not.toEval();
  27. expect(`
  28. "use strict";
  29. if (false);
  30. else function foo() {}
  31. `).not.toEval();
  32. expect(`
  33. "use strict";
  34. if (false) function foo() {}
  35. else function bar() {}
  36. `).not.toEval();
  37. });
  38. });