@@ -1337,6 +1337,48 @@ describe('ngModel', function() {
1337
1337
} ) ;
1338
1338
1339
1339
} ) ;
1340
+
1341
+ describe ( 'override ModelOptions' , function ( ) {
1342
+ it ( 'should replace the previous model options' , function ( ) {
1343
+ var $options = ctrl . $options ;
1344
+ ctrl . $overrideModelOptions ( { } ) ;
1345
+ expect ( ctrl . $options ) . not . toBe ( $options ) ;
1346
+ } ) ;
1347
+
1348
+ it ( 'should set the given options' , function ( ) {
1349
+ var $options = ctrl . $options ;
1350
+ ctrl . $overrideModelOptions ( { debounce : 1000 , updateOn : 'blur' } ) ;
1351
+ expect ( ctrl . $options . getOption ( 'debounce' ) ) . toEqual ( 1000 ) ;
1352
+ expect ( ctrl . $options . getOption ( 'updateOn' ) ) . toEqual ( 'blur' ) ;
1353
+ expect ( ctrl . $options . getOption ( 'updateOnDefault' ) ) . toBe ( false ) ;
1354
+ } ) ;
1355
+
1356
+ it ( 'should inherit from a parent model options if specified' , inject ( function ( $compile , $rootScope ) {
1357
+ var element = $compile (
1358
+ '<form name="form" ng-model-options="{debounce: 1000, updateOn: \'blur\'}">' +
1359
+ ' <input ng-model="value" name="input">' +
1360
+ '</form>' ) ( $rootScope ) ;
1361
+ var ctrl = $rootScope . form . input ;
1362
+ ctrl . $overrideModelOptions ( { debounce : 2000 , '*' : '$inherit' } ) ;
1363
+ expect ( ctrl . $options . getOption ( 'debounce' ) ) . toEqual ( 2000 ) ;
1364
+ expect ( ctrl . $options . getOption ( 'updateOn' ) ) . toEqual ( 'blur' ) ;
1365
+ expect ( ctrl . $options . getOption ( 'updateOnDefault' ) ) . toBe ( false ) ;
1366
+ dealoc ( element ) ;
1367
+ } ) ) ;
1368
+
1369
+ it ( 'should not inherit from a parent model options if not specified' , inject ( function ( $compile , $rootScope ) {
1370
+ var element = $compile (
1371
+ '<form name="form" ng-model-options="{debounce: 1000, updateOn: \'blur\'}">' +
1372
+ ' <input ng-model="value" name="input">' +
1373
+ '</form>' ) ( $rootScope ) ;
1374
+ var ctrl = $rootScope . form . input ;
1375
+ ctrl . $overrideModelOptions ( { debounce : 2000 } ) ;
1376
+ expect ( ctrl . $options . getOption ( 'debounce' ) ) . toEqual ( 2000 ) ;
1377
+ expect ( ctrl . $options . getOption ( 'updateOn' ) ) . toEqual ( '' ) ;
1378
+ expect ( ctrl . $options . getOption ( 'updateOnDefault' ) ) . toBe ( true ) ;
1379
+ dealoc ( element ) ;
1380
+ } ) ) ;
1381
+ } ) ;
1340
1382
} ) ;
1341
1383
1342
1384
0 commit comments