| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | test("length is 3", () => { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   expect(Reflect.defineProperty).toHaveLength(3); | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | describe("errors", () => { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("target must be an object", () => { | 
					
						
							|  |  |  |     [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { | 
					
						
							|  |  |  |       expect(() => { | 
					
						
							|  |  |  |         Reflect.defineProperty(value); | 
					
						
							|  |  |  |       }).toThrowWithMessage( | 
					
						
							|  |  |  |         TypeError, | 
					
						
							|  |  |  |         "First argument of Reflect.defineProperty() must be an object" | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("descriptor must be an object", () => { | 
					
						
							|  |  |  |     [null, undefined, "foo", 123, NaN, Infinity].forEach(value => { | 
					
						
							|  |  |  |       expect(() => { | 
					
						
							|  |  |  |         Reflect.defineProperty({}, "foo", value); | 
					
						
							|  |  |  |       }).toThrowWithMessage(TypeError, "Descriptor argument is not an object"); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | describe("normal behavior", () => { | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("initial value and non-writable", () => { | 
					
						
							|  |  |  |     var o = {}; | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     expect(Reflect.defineProperty(o, "foo", { value: 1, writable: false })).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |     o.foo = 2; | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("initial value and writable", () => { | 
					
						
							|  |  |  |     var o = {}; | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     expect(Reflect.defineProperty(o, "foo", { value: 1, writable: true })).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |     o.foo = 2; | 
					
						
							|  |  |  |     expect(o.foo).toBe(2); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("can redefine value of configurable, writable property", () => { | 
					
						
							|  |  |  |     var o = {}; | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: true }) | 
					
						
							|  |  |  |     ).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |     expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(2); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("can redefine value of configurable, non-writable property", () => { | 
					
						
							|  |  |  |     var o = {}; | 
					
						
							| 
									
										
										
										
											2020-05-01 11:06:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       Reflect.defineProperty(o, "foo", { value: 1, configurable: true, writable: false }) | 
					
						
							|  |  |  |     ).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |     expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(2); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |   test("cannot redefine value of non-configurable, non-writable property", () => { | 
					
						
							|  |  |  |     var o = {}; | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-05 09:27:00 -07:00
										 |  |  |     expect(o.foo).toBeUndefined(); | 
					
						
							|  |  |  |     expect( | 
					
						
							|  |  |  |       Reflect.defineProperty(o, "foo", { value: 1, configurable: false, writable: false }) | 
					
						
							|  |  |  |     ).toBeTrue(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |     expect(Reflect.defineProperty(o, "foo", { value: 2 })).toBeFalse(); | 
					
						
							|  |  |  |     expect(o.foo).toBe(1); | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2020-07-04 15:42:19 +01:00
										 |  |  | }); |