@@ -1200,6 +1200,52 @@ describe('form', function() {
1200
1200
} ) ;
1201
1201
} ) ;
1202
1202
1203
+ describe ( '$getControls' , function ( ) {
1204
+ it ( 'should return an empty array if the controller has no controls' , function ( ) {
1205
+ doc = $compile ( '<form name="testForm"></form>' ) ( scope ) ;
1206
+
1207
+ scope . $digest ( ) ;
1208
+
1209
+ var formCtrl = scope . testForm ;
1210
+
1211
+ expect ( formCtrl . $getControls ( ) ) . toEqual ( [ ] ) ;
1212
+ } ) ;
1213
+
1214
+ it ( 'should return a shallow copy of the form controls' , function ( ) {
1215
+ doc = $compile (
1216
+ '<form name="testForm">' +
1217
+ '<input ng-model="named" name="foo">' +
1218
+ '<div ng-form>' +
1219
+ '<input ng-model="named" name="foo">' +
1220
+ '</div>' +
1221
+ '</form>' ) ( scope ) ;
1222
+
1223
+ scope . $digest ( ) ;
1224
+
1225
+ var form = doc ,
1226
+ formCtrl = scope . testForm ,
1227
+ formInput = form . children ( 'input' ) . eq ( 0 ) ,
1228
+ formInputCtrl = formInput . controller ( 'ngModel' ) ,
1229
+ nestedForm = form . find ( 'div' ) ,
1230
+ nestedFormCtrl = nestedForm . controller ( 'form' ) ,
1231
+ nestedInput = nestedForm . children ( 'input' ) . eq ( 0 ) ,
1232
+ nestedInputCtrl = nestedInput . controller ( 'ngModel' ) ;
1233
+
1234
+ var controls = formCtrl . $getControls ( ) ;
1235
+
1236
+ expect ( controls ) . not . toBe ( formCtrl . $$controls ) ;
1237
+
1238
+ controls . push ( 'something' ) ;
1239
+ expect ( formCtrl . $$controls ) . not . toContain ( 'something' ) ;
1240
+
1241
+ expect ( controls [ 0 ] ) . toBe ( formInputCtrl ) ;
1242
+ expect ( controls [ 1 ] ) . toBe ( nestedFormCtrl ) ;
1243
+
1244
+ var nestedControls = controls [ 1 ] . $getControls ( ) ;
1245
+
1246
+ expect ( nestedControls [ 0 ] ) . toBe ( nestedInputCtrl ) ;
1247
+ } ) ;
1248
+ } ) ;
1203
1249
1204
1250
it ( 'should rename nested form controls when interpolated name changes' , function ( ) {
1205
1251
scope . idA = 'A' ;
0 commit comments