| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("extending function", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A extends function () { | 
					
						
							|  |  |  |         this.foo = 10; | 
					
						
							|  |  |  |     } {} | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(new A().foo).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("extending null", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A extends null {} | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(Object.getPrototypeOf(A.prototype)).toBeNull(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(() => { | 
					
						
							|  |  |  |         new A(); | 
					
						
							|  |  |  |     }).toThrowWithMessage(ReferenceError, "|this| has not been initialized"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("extending String", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class MyString extends String {} | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const ms = new MyString("abc"); | 
					
						
							|  |  |  |     expect(ms).toBeInstanceOf(MyString); | 
					
						
							|  |  |  |     expect(ms).toBeInstanceOf(String); | 
					
						
							|  |  |  |     expect(ms.charAt(1)).toBe("b"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class MyString2 extends MyString { | 
					
						
							|  |  |  |         charAt(i) { | 
					
						
							|  |  |  |             return `#${super.charAt(i)}`; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const ms2 = new MyString2("abc"); | 
					
						
							|  |  |  |     expect(ms2.charAt(1)).toBe("#b"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |