@@ -429,6 +429,73 @@ describe('select', function() {
429
429
expect ( select . find ( 'option' ) . length ) . toEqual ( 1 ) ;
430
430
} ) ;
431
431
} ) ;
432
+
433
+ describe ( 'blank option' , function ( ) {
434
+
435
+ function createSelect ( attrs , blank , unknown ) {
436
+ var html = '<select' ;
437
+ forEach ( attrs , function ( value , key ) {
438
+ if ( isBoolean ( value ) ) {
439
+ if ( value ) html += ' ' + key ;
440
+ } else {
441
+ html += ' ' + key + '="' + value + '"' ;
442
+ }
443
+ } ) ;
444
+ html += '>' +
445
+ ( blank ? blank : '' ) +
446
+ ( unknown ? unknown : '' ) +
447
+ '</select>' ;
448
+ select = jqLite ( html ) ;
449
+ scope = compile ( select ) ;
450
+ }
451
+
452
+ function createSingleSelect ( blank , unknown ) {
453
+ createSelect ( {
454
+ 'ng:model' :'selected' ,
455
+ 'ng:options' :'value.name for value in values'
456
+ } , blank , unknown ) ;
457
+ }
458
+
459
+ it ( 'should be compiled as template, be watched and updated' , function ( ) {
460
+ var option ;
461
+
462
+ createSingleSelect ( '<option value="">blank is {{blankTemplate}}</option>' ) ;
463
+ scope . blankTemplate = 'so blank' ;
464
+ scope . values = [ { name :'A' } ] ;
465
+ scope . $digest ( ) ;
466
+
467
+ // check blank option is first and is compiled
468
+ expect ( select . find ( 'option' ) . length == 2 ) ;
469
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
470
+ expect ( option . val ( ) ) . toBe ( '' ) ;
471
+ expect ( option . text ( ) ) . toBe ( 'blank is so blank' ) ;
472
+
473
+ // change blankTemplate and $digest
474
+ scope . blankTemplate = 'not so blank' ;
475
+ scope . $digest ( ) ;
476
+
477
+ // check blank option is first and is compiled
478
+ expect ( select . find ( 'option' ) . length == 2 ) ;
479
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
480
+ expect ( option . val ( ) ) . toBe ( '' ) ;
481
+ expect ( option . text ( ) ) . toBe ( 'blank is not so blank' ) ;
482
+ } ) ;
483
+
484
+ it ( 'should be compiled from ng:bind-template attribute if given instead of text' , function ( ) {
485
+ var option ;
486
+
487
+ createSingleSelect ( '<option value="" ng:bind-template="blank is {{blankTemplate}}"></option>' ) ;
488
+ scope . blankTemplate = 'so blank' ;
489
+ scope . values = [ { name :'A' } ] ;
490
+ scope . $digest ( ) ;
491
+
492
+ // check blank option is first and is compiled
493
+ expect ( select . find ( 'option' ) . length == 2 ) ;
494
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
495
+ expect ( option . val ( ) ) . toBe ( '' ) ;
496
+ expect ( option . text ( ) ) . toBe ( 'blank is so blank' ) ;
497
+ } ) ;
498
+ } ) ;
432
499
433
500
describe ( 'on change' , function ( ) {
434
501
it ( 'should update model on change' , function ( ) {
0 commit comments