@@ -37,6 +37,89 @@ describe('ngRepeat', function() {
3737 } ) ) ;
3838
3939
40+ it ( 'should ngRepeat over array of primitive correctly' , inject ( function ( $rootScope , $compile ) {
41+ element = $compile (
42+ '<ul>' +
43+ '<li ng-repeat="item in items" ng-init="suffix = \';\'" ng-bind="item + suffix"></li>' +
44+ '</ul>' ) ( $rootScope ) ;
45+
46+ Array . prototype . extraProperty = "should be ignored" ;
47+ // INIT
48+ $rootScope . items = [ true , true , true ] ;
49+ $rootScope . $digest ( ) ;
50+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
51+ expect ( element . text ( ) ) . toEqual ( 'true;true;true;' ) ;
52+ delete Array . prototype . extraProperty ;
53+
54+ $rootScope . items = [ false , true , true ] ;
55+ $rootScope . $digest ( ) ;
56+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
57+ expect ( element . text ( ) ) . toEqual ( 'false;true;true;' ) ;
58+
59+ $rootScope . items = [ false , true , false ] ;
60+ $rootScope . $digest ( ) ;
61+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
62+ expect ( element . text ( ) ) . toEqual ( 'false;true;false;' ) ;
63+
64+ $rootScope . items = [ true ] ;
65+ $rootScope . $digest ( ) ;
66+ expect ( element . find ( 'li' ) . length ) . toEqual ( 1 ) ;
67+ expect ( element . text ( ) ) . toEqual ( 'true;' ) ;
68+
69+ $rootScope . items = [ true , true , false ] ;
70+ $rootScope . $digest ( ) ;
71+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
72+ expect ( element . text ( ) ) . toEqual ( 'true;true;false;' ) ;
73+
74+ $rootScope . items = [ true , false , false ] ;
75+ $rootScope . $digest ( ) ;
76+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
77+ expect ( element . text ( ) ) . toEqual ( 'true;false;false;' ) ;
78+
79+ // string
80+ $rootScope . items = [ 'a' , 'a' , 'a' ] ;
81+ $rootScope . $digest ( ) ;
82+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
83+ expect ( element . text ( ) ) . toEqual ( 'a;a;a;' ) ;
84+
85+ $rootScope . items = [ 'ab' , 'a' , 'a' ] ;
86+ $rootScope . $digest ( ) ;
87+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
88+ expect ( element . text ( ) ) . toEqual ( 'ab;a;a;' ) ;
89+
90+ $rootScope . items = [ 'test' ] ;
91+ $rootScope . $digest ( ) ;
92+ expect ( element . find ( 'li' ) . length ) . toEqual ( 1 ) ;
93+ expect ( element . text ( ) ) . toEqual ( 'test;' ) ;
94+
95+ $rootScope . items = [ 'same' , 'value' ] ;
96+ $rootScope . $digest ( ) ;
97+ expect ( element . find ( 'li' ) . length ) . toEqual ( 2 ) ;
98+ expect ( element . text ( ) ) . toEqual ( 'same;value;' ) ;
99+
100+ // number
101+ $rootScope . items = [ 12 , 12 , 12 ] ;
102+ $rootScope . $digest ( ) ;
103+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
104+ expect ( element . text ( ) ) . toEqual ( '12;12;12;' ) ;
105+
106+ $rootScope . items = [ 53 , 12 , 27 ] ;
107+ $rootScope . $digest ( ) ;
108+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
109+ expect ( element . text ( ) ) . toEqual ( '53;12;27;' ) ;
110+
111+ $rootScope . items = [ 89 ] ;
112+ $rootScope . $digest ( ) ;
113+ expect ( element . find ( 'li' ) . length ) . toEqual ( 1 ) ;
114+ expect ( element . text ( ) ) . toEqual ( '89;' ) ;
115+
116+ $rootScope . items = [ 89 , 23 ] ;
117+ $rootScope . $digest ( ) ;
118+ expect ( element . find ( 'li' ) . length ) . toEqual ( 2 ) ;
119+ expect ( element . text ( ) ) . toEqual ( '89;23;' ) ;
120+ } ) ) ;
121+
122+
40123 it ( 'should ngRepeat over object' , inject ( function ( $rootScope , $compile ) {
41124 element = $compile (
42125 '<ul>' +
@@ -47,6 +130,38 @@ describe('ngRepeat', function() {
47130 expect ( element . text ( ) ) . toEqual ( 'misko:swe;shyam:set;' ) ;
48131 } ) ) ;
49132
133+
134+ it ( 'should ngRepeat over object with primitive value correctly' , inject ( function ( $rootScope , $compile ) {
135+ element = $compile (
136+ '<ul>' +
137+ '<li ng-repeat="(key, value) in items" ng-bind="key + \':\' + value + \';\' "></li>' +
138+ '</ul>' ) ( $rootScope ) ;
139+ $rootScope . items = { misko :'true' , shyam :'true' , zhenbo : 'true' } ;
140+ $rootScope . $digest ( ) ;
141+ expect ( element . find ( 'li' ) . length ) . toEqual ( 3 ) ;
142+ 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 ) ;
147+ 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;' ) ;
158+
159+ $rootScope . items = { shyam :'true' , zhenbo : 'false' } ;
160+ $rootScope . $digest ( ) ;
161+ expect ( element . find ( 'li' ) . length ) . toEqual ( 2 ) ;
162+ expect ( element . text ( ) ) . toEqual ( 'shyam:true;zhenbo:false;' ) ;
163+ } ) ) ;
164+
50165
51166 it ( 'should not ngRepeat over parent properties' , inject ( function ( $rootScope , $compile ) {
52167 var Class = function ( ) { } ;
0 commit comments