@@ -664,6 +664,30 @@ describe('input', function() {
664
664
} ) ;
665
665
666
666
667
+ it ( 'should bind to a getter' , function ( ) {
668
+ compileInput ( '<input type="text" ng-model="name" name="alias" ng-change="change()" />' ) ;
669
+
670
+ scope . $apply ( function ( ) {
671
+ scope . name = function ( ) { return 'misko' ; } ;
672
+ } ) ;
673
+
674
+ expect ( inputElm . val ( ) ) . toBe ( 'misko' ) ;
675
+ } ) ;
676
+
677
+
678
+ it ( 'should bind to a setter' , function ( ) {
679
+ compileInput ( '<input type="text" ng-model="name" name="alias" ng-change="change()" />' ) ;
680
+
681
+ var name = '' ;
682
+ scope . name = function ( newName ) {
683
+ return typeof newName !== 'undefined' ? ( name = newName ) : name ;
684
+ } ;
685
+ changeInputValueTo ( 'adam' ) ;
686
+ expect ( inputElm . val ( ) ) . toBe ( 'adam' ) ;
687
+ expect ( name ) . toBe ( 'adam' ) ;
688
+ } ) ;
689
+
690
+
667
691
it ( 'should not set readonly or disabled property on ie7' , function ( ) {
668
692
this . addMatchers ( {
669
693
toBeOff : function ( attributeName ) {
@@ -1213,6 +1237,54 @@ describe('input', function() {
1213
1237
expect ( inputElm . val ( ) ) . toBe ( '' ) ;
1214
1238
} ) ) ;
1215
1239
1240
+ it ( 'should not try to invoke a model if getterSetter is false' , function ( ) {
1241
+ compileInput (
1242
+ '<input type="text" ng-model="name" ' +
1243
+ 'ng-model-options="{ getterSetter: false }" />' ) ;
1244
+
1245
+ var spy = scope . name = jasmine . createSpy ( 'setterSpy' ) ;
1246
+ changeInputValueTo ( 'a' ) ;
1247
+ expect ( spy ) . not . toHaveBeenCalled ( ) ;
1248
+ expect ( inputElm . val ( ) ) . toBe ( 'a' ) ;
1249
+ } ) ;
1250
+
1251
+ it ( 'should always try to invoke a model if getterSetter is true' , function ( ) {
1252
+ compileInput (
1253
+ '<input type="text" ng-model="name" ' +
1254
+ 'ng-model-options="{ getterSetter: true }" />' ) ;
1255
+
1256
+ var spy = scope . name = jasmine . createSpy ( 'setterSpy' ) . andCallFake ( function ( ) {
1257
+ return 'b' ;
1258
+ } ) ;
1259
+ changeInputValueTo ( 'a' ) ;
1260
+ expect ( inputElm . val ( ) ) . toBe ( 'b' ) ;
1261
+ expect ( spy ) . toHaveBeenCalledWith ( 'a' ) ;
1262
+ expect ( scope . name ) . toBe ( spy ) ;
1263
+
1264
+ scope . name = 'c' ;
1265
+ changeInputValueTo ( 'd' ) ;
1266
+ expect ( inputElm . val ( ) ) . toBe ( 'c' ) ;
1267
+ } ) ;
1268
+
1269
+ it ( 'should try to invoke a model if getterSetter is "auto" and model is a function' , function ( $timeout ) {
1270
+ compileInput (
1271
+ '<input type="text" ng-model="name" ' +
1272
+ 'ng-model-options="{ getterSetter: \'auto\' }" />' ) ;
1273
+
1274
+ var spy = scope . name = jasmine . createSpy ( 'setterSpy' ) . andCallFake ( function ( ) {
1275
+ return 'b' ;
1276
+ } ) ;
1277
+ changeInputValueTo ( 'a' ) ;
1278
+ expect ( inputElm . val ( ) ) . toBe ( 'b' ) ;
1279
+ expect ( spy ) . toHaveBeenCalledWith ( 'a' ) ;
1280
+ expect ( scope . name ) . toBe ( spy ) ;
1281
+
1282
+ scope . name = 'c' ;
1283
+ changeInputValueTo ( 'd' ) ;
1284
+ expect ( inputElm . val ( ) ) . toBe ( 'd' ) ;
1285
+ expect ( scope . name ) . toBe ( 'd' ) ;
1286
+ } ) ;
1287
+
1216
1288
} ) ;
1217
1289
1218
1290
it ( 'should allow complex reference binding' , function ( ) {
0 commit comments