| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("method inheritance", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             return 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent {} | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.method()).toBe(3); | 
					
						
							|  |  |  |     expect(c.method()).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("method overriding", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             return 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             return 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.method()).toBe(3); | 
					
						
							|  |  |  |     expect(c.method()).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("parent method reference with super", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             return 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             return super.method() * 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.method()).toBe(3); | 
					
						
							|  |  |  |     expect(c.method()).toBe(6); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("child class access to parent class initialized properties", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             this.x = 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent {} | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.x).toBe(3); | 
					
						
							|  |  |  |     expect(c.x).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("child class modification of parent class properties", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             this.x = 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         change() { | 
					
						
							|  |  |  |             this.x = 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.x).toBe(3); | 
					
						
							|  |  |  |     expect(c.x).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     c.change(); | 
					
						
							|  |  |  |     expect(c.x).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inheritance and hasOwnProperty", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             this.x = 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         method() { | 
					
						
							|  |  |  |             this.y = 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     const p = new Parent(); | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(p.hasOwnProperty("x")).toBeTrue(); | 
					
						
							|  |  |  |     expect(p.hasOwnProperty("y")).toBeFalse(); | 
					
						
							|  |  |  |     expect(c.hasOwnProperty("x")).toBeTrue(); | 
					
						
							|  |  |  |     expect(c.hasOwnProperty("y")).toBeFalse(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     c.method(); | 
					
						
							|  |  |  |     expect(c.hasOwnProperty("x")).toBeTrue(); | 
					
						
							|  |  |  |     expect(c.hasOwnProperty("y")).toBeTrue(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("super constructor call from child class with argument", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         constructor(x) { | 
					
						
							|  |  |  |             this.x = x; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             super(10); | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const p = new Parent(3); | 
					
						
							|  |  |  |     const c = new Child(3); | 
					
						
							|  |  |  |     expect(p.x).toBe(3); | 
					
						
							|  |  |  |     expect(c.x).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2021-05-11 23:31:30 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("issue #7045, super constructor call from child class in catch {}", () => { | 
					
						
							|  |  |  |     class Parent { | 
					
						
							|  |  |  |         constructor(x) { | 
					
						
							|  |  |  |             this.x = x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         constructor() { | 
					
						
							|  |  |  |             try { | 
					
						
							|  |  |  |                 throw new Error("Error in Child constructor"); | 
					
						
							|  |  |  |             } catch (e) { | 
					
						
							|  |  |  |                 super(e.message); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(c.x).toBe("Error in Child constructor"); | 
					
						
							|  |  |  | }); |