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