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