@@ -310,6 +310,87 @@ describe('ngModel', function() {
310
310
} ) ) ;
311
311
312
312
313
+ it ( 'should always format the viewValue as a string for a blank input type when the value is present' ,
314
+ inject ( function ( $compile , $rootScope , $sniffer ) {
315
+
316
+ var form = $compile ( '<form name="form"><input name="field" ng-model="val" /></form>' ) ( $rootScope ) ;
317
+
318
+ $rootScope . val = 123 ;
319
+ $rootScope . $digest ( ) ;
320
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( '123' ) ;
321
+
322
+ $rootScope . val = null ;
323
+ $rootScope . $digest ( ) ;
324
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( null ) ;
325
+
326
+ dealoc ( form ) ;
327
+ } ) ) ;
328
+
329
+
330
+ it ( 'should always format the viewValue as a string for a `text` input type when the value is present' ,
331
+ inject ( function ( $compile , $rootScope , $sniffer ) {
332
+
333
+ var form = $compile ( '<form name="form"><input type="text" name="field" ng-model="val" /></form>' ) ( $rootScope ) ;
334
+ $rootScope . val = 123 ;
335
+ $rootScope . $digest ( ) ;
336
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( '123' ) ;
337
+
338
+ $rootScope . val = null ;
339
+ $rootScope . $digest ( ) ;
340
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( null ) ;
341
+
342
+ $rootScope . val = undefined ;
343
+ $rootScope . $digest ( ) ;
344
+ expect ( $rootScope . form . field . $viewValue ) . toBeUndefined ( ) ;
345
+
346
+ dealoc ( form ) ;
347
+ } ) ) ;
348
+
349
+
350
+ it ( 'should always format the viewValue as a string for an `email` input type when the value is present' ,
351
+ inject ( function ( $compile , $rootScope , $sniffer ) {
352
+
353
+ var fakeEmail = { } ;
354
+ fakeEmail . toString = function ( ) { return 'fake@email' ; } ;
355
+ var form = $compile ( '<form name="form"><input type="email" name="field" ng-model="val" /></form>' ) ( $rootScope ) ;
356
+ $rootScope . val = fakeEmail ;
357
+ $rootScope . $digest ( ) ;
358
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( 'fake@email' ) ;
359
+
360
+ $rootScope . val = null ;
361
+ $rootScope . $digest ( ) ;
362
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( null ) ;
363
+
364
+ $rootScope . val = undefined ;
365
+ $rootScope . $digest ( ) ;
366
+ expect ( $rootScope . form . field . $viewValue ) . toBeUndefined ( ) ;
367
+
368
+ dealoc ( form ) ;
369
+ } ) ) ;
370
+
371
+
372
+ it ( 'should always format the viewValue as a string for a `url` input type when the value is present' ,
373
+ inject ( function ( $compile , $rootScope , $sniffer ) {
374
+
375
+ var fakeUrl = { } ;
376
+ fakeUrl . toString = function ( ) { return 'https://www.angularjs.org' ; } ;
377
+ var form = $compile ( '<form name="form"><input type="url" name="field" ng-model="val" /></form>' ) ( $rootScope ) ;
378
+ $rootScope . val = fakeUrl ;
379
+ $rootScope . $digest ( ) ;
380
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( 'https://www.angularjs.org' ) ;
381
+
382
+ $rootScope . val = null ;
383
+ $rootScope . $digest ( ) ;
384
+ expect ( $rootScope . form . field . $viewValue ) . toBe ( null ) ;
385
+
386
+ $rootScope . val = undefined ;
387
+ $rootScope . $digest ( ) ;
388
+ expect ( $rootScope . form . field . $viewValue ) . toBeUndefined ( ) ;
389
+
390
+ dealoc ( form ) ;
391
+ } ) ) ;
392
+
393
+
313
394
it ( 'should register/deregister a nested ngModel with parent form when entering or leaving DOM' ,
314
395
inject ( function ( $compile , $rootScope ) {
315
396
0 commit comments