| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("no arguments", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let getNumber = () => { | 
					
						
							|  |  |  |         return 42; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(getNumber()).toBe(42); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getNumber = () => 42; | 
					
						
							|  |  |  |     expect(getNumber()).toBe(42); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     getNumber = () => { | 
					
						
							|  |  |  |         return 99; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(getNumber()).toBe(99); | 
					
						
							|  |  |  |     getNumber = () => 99; | 
					
						
							|  |  |  |     expect(getNumber()).toBe(99); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("arguments", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let add = (a, b) => a + b; | 
					
						
							|  |  |  |     expect(add(2, 3)).toBe(5); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const addBlock = (a, b) => { | 
					
						
							|  |  |  |         let res = a + b; | 
					
						
							|  |  |  |         return res; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(addBlock(5, 4)).toBe(9); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("inside an array", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let chompy = [x => x, 2]; | 
					
						
							|  |  |  |     expect(chompy).toHaveLength(2); | 
					
						
							|  |  |  |     expect(chompy[0](1)).toBe(1); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("return object literal", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const makeObject = (a, b) => ({ a, b }); | 
					
						
							|  |  |  |     const obj = makeObject(33, 44); | 
					
						
							|  |  |  |     expect(typeof obj).toBe("object"); | 
					
						
							|  |  |  |     expect(obj.a).toBe(33); | 
					
						
							|  |  |  |     expect(obj.b).toBe(44); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("return undefined", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let returnUndefined = () => {}; | 
					
						
							|  |  |  |     expect(returnUndefined()).toBeUndefined(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("return array literal", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const makeArray = (a, b) => [a, b]; | 
					
						
							|  |  |  |     const array = makeArray("3", { foo: 4 }); | 
					
						
							|  |  |  |     expect(array[0]).toBe("3"); | 
					
						
							|  |  |  |     expect(array[1].foo).toBe(4); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("return numeric expression", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let square = x => x * x; | 
					
						
							|  |  |  |     expect(square(3)).toBe(9); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let squareBlock = x => { | 
					
						
							|  |  |  |         return x * x; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     expect(squareBlock(4)).toBe(16); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("return called arrow function expression", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const message = (who => "Hello " + who)("friends!"); | 
					
						
							|  |  |  |     expect(message).toBe("Hello friends!"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const sum = ((x, y, z) => x + y + z)(1, 2, 3); | 
					
						
							|  |  |  |     expect(sum).toBe(6); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const product = ((x, y, z) => { | 
					
						
							|  |  |  |         let res = x * y * z; | 
					
						
							|  |  |  |         return res; | 
					
						
							|  |  |  |     })(5, 4, 2); | 
					
						
							|  |  |  |     expect(product).toBe(40); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const half = (x => { | 
					
						
							|  |  |  |         return x / 2; | 
					
						
							|  |  |  |     })(10); | 
					
						
							|  |  |  |     expect(half).toBe(5); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("currying", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let add = a => b => a + b; | 
					
						
							|  |  |  |     expect(typeof add(1)).toBe("function"); | 
					
						
							|  |  |  |     expect(typeof add(1, 2)).toBe("function"); | 
					
						
							|  |  |  |     expect(add(1)(2)).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("with comma operator", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let foo, bar; | 
					
						
							|  |  |  |     (foo = bar), baz => {}; | 
					
						
							|  |  |  |     expect(foo).toBe(undefined); | 
					
						
							|  |  |  |     expect(bar).toBe(undefined); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("arrow functions in objects", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     function FooBar() { | 
					
						
							|  |  |  |         this.x = { | 
					
						
							|  |  |  |             y: () => this, | 
					
						
							|  |  |  |             z: function () { | 
					
						
							|  |  |  |                 return (() => this)(); | 
					
						
							|  |  |  |             }, | 
					
						
							|  |  |  |         }; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const foobar = new FooBar(); | 
					
						
							|  |  |  |     expect(foobar.x.y()).toBe(foobar); | 
					
						
							|  |  |  |     expect(foobar.x.z()).toBe(foobar.x); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-05-30 00:13:42 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("strict mode propogation", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     (() => { | 
					
						
							|  |  |  |         "use strict"; | 
					
						
							|  |  |  |         expect(isStrictMode()).toBeTrue(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         (() => { | 
					
						
							|  |  |  |             expect(isStrictMode()).toBeTrue(); | 
					
						
							|  |  |  |         })(); | 
					
						
							|  |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2020-05-27 22:22:08 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     (() => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         "use strict"; | 
					
						
							|  |  |  |         expect(isStrictMode()).toBeTrue(); | 
					
						
							| 
									
										
										
										
											2020-05-27 22:22:08 -07:00
										 |  |  |     })(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     (() => { | 
					
						
							|  |  |  |         expect(isStrictMode()).toBeFalse(); | 
					
						
							| 
									
										
										
										
											2020-05-27 22:22:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         (() => { | 
					
						
							|  |  |  |             "use strict"; | 
					
						
							|  |  |  |             expect(isStrictMode()).toBeTrue(); | 
					
						
							|  |  |  |         })(); | 
					
						
							| 
									
										
										
										
											2020-05-27 22:22:08 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         expect(isStrictMode()).toBeFalse(); | 
					
						
							| 
									
										
										
										
											2020-05-27 22:22:08 -07:00
										 |  |  |     })(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("no prototype", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let foo = () => {}; | 
					
						
							|  |  |  |     expect(foo).not.toHaveProperty("prototype"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("cannot be constructed", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     let foo = () => {}; | 
					
						
							|  |  |  |     expect(() => { | 
					
						
							|  |  |  |         new foo(); | 
					
						
							|  |  |  |     }).toThrowWithMessage(TypeError, "foo is not a constructor"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |