Skip to content

Commit 33bff17

Browse files
committed
refactor(tests): refactor tests to clarify the behavior of onChange
1 parent 956b8c8 commit 33bff17

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

modules/angular2/change_detection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector,
1212
export {DynamicChangeDetector}
1313
from './src/change_detection/dynamic_change_detector';
1414
export * from './src/change_detection/pipes/pipe_registry';
15+
export {uninitialized} from './src/change_detection/change_detection_util';
1516
export * from './src/change_detection/pipes/pipe';
1617

17-
1818
import {ProtoChangeDetector, DynamicProtoChangeDetector, JitProtoChangeDetector}
1919
from './src/change_detection/proto_change_detector';
2020
import {PipeRegistry} from './src/change_detection/pipes/pipe_registry';

modules/angular2/src/core/compiler/view.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {DOM} from 'angular2/src/dom/dom_adapter';
22
import {Promise} from 'angular2/src/facade/async';
33
import {ListWrapper, MapWrapper, Map, StringMapWrapper, List} from 'angular2/src/facade/collection';
44
import {AST, ContextWithVariableBindings, ChangeDispatcher, ProtoChangeDetector, ChangeDetector,
5-
ChangeRecord, BindingRecord} from 'angular2/change_detection';
5+
ChangeRecord, BindingRecord, uninitialized} from 'angular2/change_detection';
66

77
import {ProtoElementInjector, ElementInjector, PreBuiltObjects} from './element_injector';
88
import {BindingPropagationConfig} from './binding_propagation_config';
@@ -682,12 +682,16 @@ class DirectiveMemento {
682682
}
683683
}
684684

685-
class PropertyUpdate {
685+
export class PropertyUpdate {
686686
currentValue;
687687
previousValue;
688688

689689
constructor(currentValue, previousValue) {
690690
this.currentValue = currentValue;
691691
this.previousValue = previousValue;
692692
}
693+
694+
static createWithoutPrevious(currentValue) {
695+
return new PropertyUpdate(currentValue, uninitialized);
696+
}
693697
}

modules/angular2/test/core/compiler/view_spec.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {List, MapWrapper} from 'angular2/src/facade/collection';
1111
import {DOM} from 'angular2/src/dom/dom_adapter';
1212
import {int, IMPLEMENTS} from 'angular2/src/facade/lang';
1313
import {Injector} from 'angular2/di';
14-
import {View} from 'angular2/src/core/compiler/view';
14+
import {View, PropertyUpdate} from 'angular2/src/core/compiler/view';
1515
import {ViewContainer} from 'angular2/src/core/compiler/view_container';
1616
import {VmTurnZone} from 'angular2/src/core/zone/vm_turn_zone';
1717
import {EventManager, DomEventsPlugin} from 'angular2/src/core/events/event_manager';
@@ -601,7 +601,7 @@ export function main() {
601601
expect(directive.c).toEqual(300);
602602
});
603603

604-
it('should provide a map of updated properties', () => {
604+
it('should provide a map of updated properties using onChange callback', () => {
605605
var pv = new ProtoView(el('<div class="ng-binding"></div>'),
606606
new DynamicProtoChangeDetector(null), null);
607607

@@ -612,16 +612,20 @@ export function main() {
612612
pv.bindDirectiveProperty( 0, parser.parseBinding('b', null), 'b', reflector.setter('b'));
613613
createViewAndChangeDetector(pv);
614614

615+
var directive = view.elementInjectors[0].get(DirectiveImplementingOnChange);
616+
615617
ctx.a = 0;
616618
ctx.b = 0;
617619
cd.detectChanges();
618620

621+
expect(directive.changes).toEqual({
622+
"a" : PropertyUpdate.createWithoutPrevious(0),
623+
"b" : PropertyUpdate.createWithoutPrevious(0)
624+
});
625+
619626
ctx.a = 100;
620627
cd.detectChanges();
621-
622-
var directive = view.elementInjectors[0].get(DirectiveImplementingOnChange);
623-
expect(directive.changes["a"].currentValue).toEqual(100);
624-
expect(directive.changes["b"]).not.toBeDefined();
628+
expect(directive.changes).toEqual({"a" : new PropertyUpdate(100, 0)});
625629
});
626630
});
627631
});

0 commit comments

Comments
 (0)