@@ -37,10 +37,10 @@ describe('ngRepeat', function() {
37
37
} ) ) ;
38
38
39
39
40
- it ( 'should ngRepeat over array of primitive correctly ' , inject ( function ( $rootScope , $compile ) {
40
+ it ( 'should ngRepeat over array of primitives ' , inject ( function ( $rootScope , $compile ) {
41
41
element = $compile (
42
42
'<ul>' +
43
- '<li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"> </li>' +
43
+ '<li ng-repeat="item in items">{{item}}; </li>' +
44
44
'</ul>' ) ( $rootScope ) ;
45
45
46
46
Array . prototype . extraProperty = "should be ignored" ;
@@ -91,13 +91,13 @@ describe('ngRepeat', function() {
91
91
$rootScope . $digest ( ) ;
92
92
expect ( element . find ( 'li' ) . length ) . toEqual ( 1 ) ;
93
93
expect ( element . text ( ) ) . toEqual ( 'test;' ) ;
94
-
94
+
95
95
$rootScope . items = [ 'same' , 'value' ] ;
96
96
$rootScope . $digest ( ) ;
97
97
expect ( element . find ( 'li' ) . length ) . toEqual ( 2 ) ;
98
98
expect ( element . text ( ) ) . toEqual ( 'same;value;' ) ;
99
-
100
- // number
99
+
100
+ // number
101
101
$rootScope . items = [ 12 , 12 , 12 ] ;
102
102
$rootScope . $digest ( ) ;
103
103
expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
@@ -130,36 +130,48 @@ describe('ngRepeat', function() {
130
130
expect ( element . text ( ) ) . toEqual ( 'misko:swe;shyam:set;' ) ;
131
131
} ) ) ;
132
132
133
-
134
- it ( 'should ngRepeat over object with primitive value correctly' , inject ( function ( $rootScope , $compile ) {
133
+
134
+ it ( 'should ngRepeat over object with changing primitive value' ,
135
+ inject ( function ( $rootScope , $compile ) {
136
+
135
137
element = $compile (
136
138
'<ul>' +
137
- '<li ng-repeat="(key, value) in items" ng-bind="key + \':\' + value + \';\' "></li>' +
139
+ '<li ng-repeat="(key, value) in items">' +
140
+ '{{key}}:{{value}};' +
141
+ '<input type="checkbox" ng-model="items[key]">' +
142
+ '</li>' +
138
143
'</ul>' ) ( $rootScope ) ;
139
- $rootScope . items = { misko :'true' , shyam :'true' , zhenbo : 'true' } ;
144
+
145
+ $rootScope . items = { misko : true , shyam : true , zhenbo :true } ;
140
146
$rootScope . $digest ( ) ;
141
147
expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
142
148
expect ( element . text ( ) ) . toEqual ( 'misko:true;shyam:true;zhenbo:true;' ) ;
143
-
144
- $rootScope . items = { misko :'false' , shyam :'true' , zhenbo : 'true' } ;
145
- $rootScope . $digest ( ) ;
146
- expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
149
+
150
+ browserTrigger ( element . find ( 'input' ) . eq ( 0 ) , 'click' ) ;
151
+
147
152
expect ( element . text ( ) ) . toEqual ( 'misko:false;shyam:true;zhenbo:true;' ) ;
148
-
149
- $rootScope . items = { misko :'false' , shyam :'false' , zhenbo : 'false' } ;
150
- $rootScope . $digest ( ) ;
151
- expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
152
- expect ( element . text ( ) ) . toEqual ( 'misko:false;shyam:false;zhenbo:false;' ) ;
153
-
154
- $rootScope . items = { misko :'true' } ;
155
- $rootScope . $digest ( ) ;
156
- expect ( element . find ( 'li' ) . length ) . toEqual ( 1 ) ;
157
- expect ( element . text ( ) ) . toEqual ( 'misko:true;' ) ;
153
+ expect ( element . find ( 'input' ) [ 0 ] . checked ) . toBe ( false ) ;
154
+ expect ( element . find ( 'input' ) [ 1 ] . checked ) . toBe ( true ) ;
155
+ expect ( element . find ( 'input' ) [ 2 ] . checked ) . toBe ( true ) ;
158
156
159
- $rootScope . items = { shyam :'true' , zhenbo : 'false' } ;
157
+ browserTrigger ( element . find ( 'input' ) . eq ( 0 ) , 'click' ) ;
158
+ expect ( element . text ( ) ) . toEqual ( 'misko:true;shyam:true;zhenbo:true;' ) ;
159
+ expect ( element . find ( 'input' ) [ 0 ] . checked ) . toBe ( true ) ;
160
+ expect ( element . find ( 'input' ) [ 1 ] . checked ) . toBe ( true ) ;
161
+ expect ( element . find ( 'input' ) [ 2 ] . checked ) . toBe ( true ) ;
162
+
163
+ browserTrigger ( element . find ( 'input' ) . eq ( 1 ) , 'click' ) ;
164
+ expect ( element . text ( ) ) . toEqual ( 'misko:true;shyam:false;zhenbo:true;' ) ;
165
+ expect ( element . find ( 'input' ) [ 0 ] . checked ) . toBe ( true ) ;
166
+ expect ( element . find ( 'input' ) [ 1 ] . checked ) . toBe ( false ) ;
167
+ expect ( element . find ( 'input' ) [ 2 ] . checked ) . toBe ( true ) ;
168
+
169
+ $rootScope . items = { misko : false , shyam : true , zhenbo : true } ;
160
170
$rootScope . $digest ( ) ;
161
- expect ( element . find ( 'li' ) . length ) . toEqual ( 2 ) ;
162
- expect ( element . text ( ) ) . toEqual ( 'shyam:true;zhenbo:false;' ) ;
171
+ expect ( element . text ( ) ) . toEqual ( 'misko:false;shyam:true;zhenbo:true;' ) ;
172
+ expect ( element . find ( 'input' ) [ 0 ] . checked ) . toBe ( false ) ;
173
+ expect ( element . find ( 'input' ) [ 1 ] . checked ) . toBe ( true ) ;
174
+ expect ( element . find ( 'input' ) [ 2 ] . checked ) . toBe ( true ) ;
163
175
} ) ) ;
164
176
165
177
0 commit comments