refactor(tests): refactor tests to clarify the behavior of onChange
This commit is contained in:
		
							parent
							
								
									956b8c8792
								
							
						
					
					
						commit
						33bff17f33
					
				
							
								
								
									
										2
									
								
								modules/angular2/change_detection.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								modules/angular2/change_detection.js
									
									
									
									
										vendored
									
									
								
							| @ -12,9 +12,9 @@ export {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector, | ||||
| export {DynamicChangeDetector} | ||||
|     from './src/change_detection/dynamic_change_detector'; | ||||
| export * from './src/change_detection/pipes/pipe_registry'; | ||||
| export {uninitialized} from './src/change_detection/change_detection_util'; | ||||
| export * from './src/change_detection/pipes/pipe'; | ||||
| 
 | ||||
| 
 | ||||
| import {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector} | ||||
|     from './src/change_detection/proto_change_detector'; | ||||
| import {PipeRegistry} from './src/change_detection/pipes/pipe_registry'; | ||||
|  | ||||
							
								
								
									
										8
									
								
								modules/angular2/src/core/compiler/view.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										8
									
								
								modules/angular2/src/core/compiler/view.js
									
									
									
									
										vendored
									
									
								
							| @ -2,7 +2,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter'; | ||||
| import {Promise} from 'angular2/src/facade/async'; | ||||
| import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection'; | ||||
| import {AST, ContextWithVariableBindings, ChangeDispatcher, ProtoChangeDetector, ChangeDetector, | ||||
|   ChangeRecord, BindingRecord} from 'angular2/change_detection'; | ||||
|   ChangeRecord, BindingRecord, uninitialized} from 'angular2/change_detection'; | ||||
| 
 | ||||
| import {ProtoElementInjector, ElementInjector, PreBuiltObjects} from './element_injector'; | ||||
| import {BindingPropagationConfig} from './binding_propagation_config'; | ||||
| @ -682,7 +682,7 @@ class DirectiveMemento { | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| class PropertyUpdate { | ||||
| export class PropertyUpdate { | ||||
|   currentValue; | ||||
|   previousValue; | ||||
| 
 | ||||
| @ -690,4 +690,8 @@ class PropertyUpdate { | ||||
|     this.currentValue = currentValue; | ||||
|     this.previousValue = previousValue; | ||||
|   } | ||||
| 
 | ||||
|   static createWithoutPrevious(currentValue) { | ||||
|     return new PropertyUpdate(currentValue, uninitialized); | ||||
|   } | ||||
| } | ||||
|  | ||||
							
								
								
									
										16
									
								
								modules/angular2/test/core/compiler/view_spec.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										16
									
								
								modules/angular2/test/core/compiler/view_spec.js
									
									
									
									
										vendored
									
									
								
							| @ -11,7 +11,7 @@ import {List, MapWrapper} from 'angular2/src/facade/collection'; | ||||
| import {DOM} from 'angular2/src/dom/dom_adapter'; | ||||
| import {int, IMPLEMENTS} from 'angular2/src/facade/lang'; | ||||
| import {Injector} from 'angular2/di'; | ||||
| import {View} from 'angular2/src/core/compiler/view'; | ||||
| import {View, PropertyUpdate} from 'angular2/src/core/compiler/view'; | ||||
| import {ViewContainer} from 'angular2/src/core/compiler/view_container'; | ||||
| import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone'; | ||||
| import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager'; | ||||
| @ -601,7 +601,7 @@ export function main() { | ||||
|           expect(directive.c).toEqual(300); | ||||
|         }); | ||||
| 
 | ||||
|         it('should provide a map of updated properties', () => { | ||||
|         it('should provide a map of updated properties using onChange callback', () => { | ||||
|           var pv = new ProtoView(el('<div class="ng-binding"></div>'), | ||||
|             new DynamicProtoChangeDetector(null), null); | ||||
| 
 | ||||
| @ -612,16 +612,20 @@ export function main() { | ||||
|           pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b')); | ||||
|           createViewAndChangeDetector(pv); | ||||
| 
 | ||||
|           var directive = view.elementInjectors[0].get(DirectiveImplementingOnChange); | ||||
| 
 | ||||
|           ctx.a = 0; | ||||
|           ctx.b = 0; | ||||
|           cd.detectChanges(); | ||||
| 
 | ||||
|           expect(directive.changes).toEqual({ | ||||
|             "a" : PropertyUpdate.createWithoutPrevious(0), | ||||
|             "b" : PropertyUpdate.createWithoutPrevious(0) | ||||
|           }); | ||||
| 
 | ||||
|           ctx.a = 100; | ||||
|           cd.detectChanges(); | ||||
| 
 | ||||
|           var directive = view.elementInjectors[0].get(DirectiveImplementingOnChange); | ||||
|           expect(directive.changes["a"].currentValue).toEqual(100); | ||||
|           expect(directive.changes["b"]).not.toBeDefined(); | ||||
|           expect(directive.changes).toEqual({"a" : new PropertyUpdate(100, 0)}); | ||||
|         }); | ||||
|       }); | ||||
|     }); | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user