| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | test("basic functionality", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return this._x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         set x(value) { | 
					
						
							|  |  |  |             this._x = value * 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(A.x).toBeUndefined(); | 
					
						
							|  |  |  |     expect(A).not.toHaveProperty("_x"); | 
					
						
							|  |  |  |     const a = new A(); | 
					
						
							|  |  |  |     expect(a.x).toBeUndefined(); | 
					
						
							|  |  |  |     expect(a).not.toHaveProperty("_x"); | 
					
						
							|  |  |  |     a.x = 3; | 
					
						
							|  |  |  |     expect(a.x).toBe(6); | 
					
						
							|  |  |  |     expect(a).toHaveProperty("_x", 6); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("name", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class A { | 
					
						
							|  |  |  |         set x(v) {} | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											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.set.name).toBe("set 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 { | 
					
						
							|  |  |  |         set "method with space"(value) { | 
					
						
							|  |  |  |             this.a = value; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         set 12(value) { | 
					
						
							|  |  |  |             this.b = value; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         set [`he${"llo"}`](value) { | 
					
						
							|  |  |  |             this.c = value; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |         set [s](value) { | 
					
						
							|  |  |  |             this.d = value; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const a = new A(); | 
					
						
							|  |  |  |     a["method with space"] = 1; | 
					
						
							|  |  |  |     a[12] = 2; | 
					
						
							|  |  |  |     a.hello = 3; | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |     a[s] = 4; | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(a.a).toBe(1); | 
					
						
							|  |  |  |     expect(a.b).toBe(2); | 
					
						
							|  |  |  |     expect(a.c).toBe(3); | 
					
						
							| 
									
										
										
										
											2020-07-07 21:39:36 -07:00
										 |  |  |     expect(a.d).toBe(4); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inherited setter", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return this._x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         set x(value) { | 
					
						
							|  |  |  |             this._x = value * 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											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 c = new Child(); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     expect(c.x).toBeUndefined(); | 
					
						
							|  |  |  |     c.x = 10; | 
					
						
							|  |  |  |     expect(c.x).toBe(20); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test("inherited static setter overriding", () => { | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return this._x; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         set x(value) { | 
					
						
							|  |  |  |             this._x = value * 2; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     class Child extends Parent { | 
					
						
							|  |  |  |         get x() { | 
					
						
							|  |  |  |             return this._x; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |         set x(value) { | 
					
						
							|  |  |  |             this._x = value * 3; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-06 07:37:45 -07:00
										 |  |  |     const c = new Child(); | 
					
						
							|  |  |  |     expect(c.x).toBeUndefined(); | 
					
						
							|  |  |  |     c.x = 10; | 
					
						
							|  |  |  |     expect(c.x).toBe(30); | 
					
						
							| 
									
										
										
										
											2020-07-05 17:26:26 -07:00
										 |  |  | }); |