Serenity Operating System
at master 39 lines 1.1 kB view raw
1test("basic functionality", () => { 2 let callHoisted = hoisted(); 3 function hoisted() { 4 return "foo"; 5 } 6 expect(hoisted()).toBe("foo"); 7 expect(callHoisted).toBe("foo"); 8}); 9 10// First two calls produce a ReferenceError, but the declarations should be hoisted 11test("functions are hoisted across non-lexical scopes", () => { 12 expect(scopedHoisted).toBeUndefined(); 13 expect(callScopedHoisted).toBeUndefined(); 14 { 15 var callScopedHoisted = scopedHoisted(); 16 function scopedHoisted() { 17 return "foo"; 18 } 19 expect(scopedHoisted()).toBe("foo"); 20 expect(callScopedHoisted).toBe("foo"); 21 } 22 expect(scopedHoisted()).toBe("foo"); 23 expect(callScopedHoisted).toBe("foo"); 24}); 25 26test("functions are not hoisted across lexical scopes", () => { 27 const test = () => { 28 var iife = (function () { 29 return declaredLater(); 30 })(); 31 function declaredLater() { 32 return "yay"; 33 } 34 return iife; 35 }; 36 37 expect(() => declaredLater).toThrow(ReferenceError); 38 expect(test()).toBe("yay"); 39});