@@ -841,6 +841,60 @@ describe('select', function() {
841
841
expect ( element ) . toBeDirty ( ) ;
842
842
} ) ;
843
843
844
+
845
+ describe ( 'calls to $render' , function ( ) {
846
+
847
+ var ngModelCtrl ;
848
+
849
+ beforeEach ( function ( ) {
850
+ compile (
851
+ '<select name="select" ng-model="selection" multiple>' +
852
+ '<option>A</option>' +
853
+ '<option>B</option>' +
854
+ '</select>' ) ;
855
+
856
+ ngModelCtrl = element . controller ( 'ngModel' ) ;
857
+ spyOn ( ngModelCtrl , '$render' ) . andCallThrough ( ) ;
858
+ } ) ;
859
+
860
+
861
+ it ( 'should call $render once when the reference to the viewValue changes' , function ( ) {
862
+ scope . $apply ( function ( ) {
863
+ scope . selection = [ 'A' ] ;
864
+ } ) ;
865
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 1 ) ;
866
+
867
+ scope . $apply ( function ( ) {
868
+ scope . selection = [ 'A' , 'B' ] ;
869
+ } ) ;
870
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 2 ) ;
871
+
872
+ scope . $apply ( function ( ) {
873
+ scope . selection = [ ] ;
874
+ } ) ;
875
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 3 ) ;
876
+ } ) ;
877
+
878
+
879
+ it ( 'should call $render once when the viewValue deep-changes' , function ( ) {
880
+ scope . $apply ( function ( ) {
881
+ scope . selection = [ 'A' ] ;
882
+ } ) ;
883
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 1 ) ;
884
+
885
+ scope . $apply ( function ( ) {
886
+ scope . selection . push ( 'B' ) ;
887
+ } ) ;
888
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 2 ) ;
889
+
890
+ scope . $apply ( function ( ) {
891
+ scope . selection . length = 0 ;
892
+ } ) ;
893
+ expect ( ngModelCtrl . $render . calls . length ) . toBe ( 3 ) ;
894
+ } ) ;
895
+
896
+ } ) ;
897
+
844
898
} ) ;
845
899
846
900
0 commit comments