refactor(tests): refactor tests to clarify the behavior of onChange

This commit is contained in:
vsavkin 2015-03-13 17:52:27 -07:00
parent 956b8c8792
commit 33bff17f33
3 changed files with 17 additions and 9 deletions

View File

@ -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';

View File

@ -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);
}
}

View File

@ -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)});
});
});
});