| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("basic functionality", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(A).not.toHaveProperty("x"); | 
					
						
							|  |  |  |     expect(new A().x).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | test("name", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |         get x() {} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const d = Object.getOwnPropertyDescriptor(A.prototype, "x"); | 
					
						
							|  |  |  |     expect(d.get.name).toBe("get x"); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("extended name syntax", () => { | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |     const s = Symbol("foo"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |         get "method with space"() { | 
					
						
							|  |  |  |             return 1; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         get 12() { | 
					
						
							|  |  |  |             return 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         get [`he${"llo"}`]() { | 
					
						
							|  |  |  |             return 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         get [s]() { | 
					
						
							|  |  |  |             return 4; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const a = new A(); | 
					
						
							|  |  |  |     expect(a["method with space"]).toBe(1); | 
					
						
							|  |  |  |     expect(a[12]).toBe(2); | 
					
						
							|  |  |  |     expect(a.hello).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |     expect(a[s]).toBe(4); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inherited getter", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             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
										 |  |  |     expect(Child).not.toHaveProperty("x"); | 
					
						
							|  |  |  |     expect(new Child().x).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inherited getter overriding", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return 10; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(new Child().x).toBe(10); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2022-02-17 18:03:41 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | test("static getter named 'async'", () => { | 
					
						
							|  |  |  |     class A { | 
					
						
							|  |  |  |         get async() { | 
					
						
							|  |  |  |             return "getter named async"; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     const a = new A(); | 
					
						
							|  |  |  |     expect("async" in a).toBeTrue(); | 
					
						
							|  |  |  |     expect(a.async).toBe("getter named async"); | 
					
						
							|  |  |  | }); |