| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe('defineProperty', function() { | 
					
						
							|  |  |  |   it('should not throw when defining length on an array', function() { | 
					
						
							|  |  |  |     const someArray: any[] = []; | 
					
						
							|  |  |  |     expect(() => Object.defineProperty(someArray, 'length', {value: 2, writable: false})) | 
					
						
							|  |  |  |         .not.toThrow(); | 
					
						
							|  |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-07-20 00:00:33 +09:00
										 |  |  |   it('should not be able to change a frozen desc', function() { | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |     const obj = {}; | 
					
						
							|  |  |  |     const desc = Object.freeze({value: null, writable: true}); | 
					
						
							|  |  |  |     Object.defineProperty(obj, 'prop', desc); | 
					
						
							| 
									
										
										
										
											2019-07-20 00:00:33 +09:00
										 |  |  |     let objDesc: any = Object.getOwnPropertyDescriptor(obj, 'prop'); | 
					
						
							|  |  |  |     expect(objDesc.writable).toBeTruthy(); | 
					
						
							|  |  |  |     try { | 
					
						
							|  |  |  |       Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'test'}); | 
					
						
							|  |  |  |     } catch (err) { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     objDesc = Object.getOwnPropertyDescriptor(obj, 'prop'); | 
					
						
							|  |  |  |     expect(objDesc.configurable).toBeFalsy(); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |   }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   it('should not throw error when try to defineProperty with a frozen obj', function() { | 
					
						
							|  |  |  |     const obj = {}; | 
					
						
							|  |  |  |     Object.freeze(obj); | 
					
						
							| 
									
										
										
										
											2019-07-20 00:00:33 +09:00
										 |  |  |     try { | 
					
						
							|  |  |  |       Object.defineProperty(obj, 'prop', {configurable: true, writable: true, value: 'value'}); | 
					
						
							|  |  |  |     } catch (err) { | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     expect((obj as any).prop).toBeFalsy(); | 
					
						
							| 
									
										
										
										
											2019-06-01 00:56:07 +09:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2019-07-20 00:00:33 +09:00
										 |  |  | }); |