| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							|  |  |  |  * Copyright Google Inc. All Rights Reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 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
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  | import {devModeEqual} from '@angular/core/src/change_detection/change_detection_util'; | 
					
						
							| 
									
										
										
										
											2019-02-20 14:21:20 -08:00
										 |  |  | import {isDifferent} from '../../src/render3/util/misc_utils'; | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe('util', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   describe('isDifferent', () => { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |     describe('checkNoChangeMode = false', () => { | 
					
						
							|  |  |  |       it('should mark non-equal arguments as different', () => { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(isDifferent({}, {})).toBeTruthy(); | 
					
						
							|  |  |  |         expect(isDifferent('foo', 'bar')).toBeTruthy(); | 
					
						
							|  |  |  |         expect(isDifferent(0, 1)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should not mark equal arguments as different', () => { | 
					
						
							|  |  |  |         const obj = {}; | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(isDifferent(obj, obj)).toBeFalsy(); | 
					
						
							|  |  |  |         expect(isDifferent('foo', 'foo')).toBeFalsy(); | 
					
						
							|  |  |  |         expect(isDifferent(1, 1)).toBeFalsy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |       it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); }); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should mark NaN with other values as different', () => { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(isDifferent(NaN, 'foo')).toBeTruthy(); | 
					
						
							|  |  |  |         expect(isDifferent(5, NaN)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |     describe('checkNoChangeMode = true', () => { | 
					
						
							|  |  |  |       // Assert relaxed constraint in checkNoChangeMode
 | 
					
						
							|  |  |  |       it('should not mark non-equal arrays, object and function as different', () => { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(!devModeEqual([], [])).toBeFalsy(); | 
					
						
							|  |  |  |         expect(!devModeEqual(() => 0, () => 0)).toBeFalsy(); | 
					
						
							|  |  |  |         expect(!devModeEqual({}, {})).toBeFalsy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       it('should mark non-equal arguments as different', () => { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(!devModeEqual('foo', 'bar')).toBeTruthy(); | 
					
						
							|  |  |  |         expect(!devModeEqual(0, 1)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       it('should not mark equal arguments as different', () => { | 
					
						
							|  |  |  |         const obj = {}; | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(isDifferent(obj, obj)).toBeFalsy(); | 
					
						
							|  |  |  |         expect(isDifferent('foo', 'foo')).toBeFalsy(); | 
					
						
							|  |  |  |         expect(isDifferent(1, 1)).toBeFalsy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |       it('should not mark NaN as different', () => { expect(isDifferent(NaN, NaN)).toBeFalsy(); }); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |       it('should mark NaN with other values as different', () => { | 
					
						
							| 
									
										
										
										
											2018-11-21 21:14:06 -08:00
										 |  |  |         expect(isDifferent(NaN, 'foo')).toBeTruthy(); | 
					
						
							|  |  |  |         expect(isDifferent(5, NaN)).toBeTruthy(); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  |       }); | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |     }); | 
					
						
							| 
									
										
										
										
											2018-08-01 10:57:16 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 14:23:03 -08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2018-01-17 17:55:55 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | }); |