@@ -130,8 +130,8 @@ describe('select', function() {
130
130
}
131
131
} ) ;
132
132
html += '>' +
133
- ( blank ? '<option value="">blank</option>' : '' ) +
134
- ( unknown ? '<option value="?">unknown</option>' : '' ) +
133
+ ( blank ? ( isString ( blank ) ? blank : '<option value="">blank</option>' ) : '' ) +
134
+ ( unknown ? ( isString ( unknown ) ? unknown : '<option value="?">unknown</option>' ) : '' ) +
135
135
'</select>' ;
136
136
select = jqLite ( html ) ;
137
137
scope = compile ( select ) ;
@@ -445,6 +445,80 @@ describe('select', function() {
445
445
} ) ;
446
446
} ) ;
447
447
448
+
449
+ describe ( 'blank option' , function ( ) {
450
+ it ( 'should be compiled as template, be watched and updated' , function ( ) {
451
+ var option ;
452
+
453
+ createSingleSelect ( '<option value="">blank is {{blankVal}}</option>' ) ;
454
+ scope . blankVal = 'so blank' ;
455
+ scope . values = [ { name :'A' } ] ;
456
+ scope . $digest ( ) ;
457
+
458
+ // check blank option is first and is compiled
459
+ expect ( select . find ( 'option' ) . length == 2 ) ;
460
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
461
+ expect ( option . val ( ) ) . toBe ( '' ) ;
462
+ expect ( option . text ( ) ) . toBe ( 'blank is so blank' ) ;
463
+
464
+ // change blankVal and $digest
465
+ scope . blankVal = 'not so blank' ;
466
+ scope . $digest ( ) ;
467
+
468
+ // check blank option is first and is compiled
469
+ expect ( select . find ( 'option' ) . length == 2 ) ;
470
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
471
+ expect ( option . val ( ) ) . toBe ( '' ) ;
472
+ expect ( option . text ( ) ) . toBe ( 'blank is not so blank' ) ;
473
+ } ) ;
474
+
475
+ it ( 'should support binding via ng:bind-template attribute' , function ( ) {
476
+ var option ;
477
+
478
+ createSingleSelect ( '<option value="" ng:bind-template="blank is {{blankVal}}"></option>' ) ;
479
+ scope . blankVal = 'so blank' ;
480
+ scope . values = [ { name :'A' } ] ;
481
+ scope . $digest ( ) ;
482
+
483
+ // check blank option is first and is compiled
484
+ expect ( select . find ( 'option' ) . length == 2 ) ;
485
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
486
+ expect ( option . val ( ) ) . toBe ( '' ) ;
487
+ expect ( option . text ( ) ) . toBe ( 'blank is so blank' ) ;
488
+ } ) ;
489
+
490
+ it ( 'should support biding via ng:bind attribute' , function ( ) {
491
+ var option ;
492
+
493
+ createSingleSelect ( '<option value="" ng:bind="blankVal"></option>' ) ;
494
+ scope . blankVal = 'is blank' ;
495
+ scope . values = [ { name :'A' } ] ;
496
+ scope . $digest ( ) ;
497
+
498
+ // check blank option is first and is compiled
499
+ expect ( select . find ( 'option' ) . length == 2 ) ;
500
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
501
+ expect ( option . val ( ) ) . toBe ( '' ) ;
502
+ expect ( option . text ( ) ) . toBe ( 'is blank' ) ;
503
+ } ) ;
504
+
505
+ it ( 'should be rendered with the attributes preserved' , function ( ) {
506
+ var option ;
507
+
508
+ createSingleSelect ( '<option value="" class="coyote" id="road-runner" ' +
509
+ 'custom-attr="custom-attr">{{blankVal}}</option>' ) ;
510
+ scope . blankVal = 'is blank' ;
511
+ scope . $digest ( ) ;
512
+
513
+ // check blank option is first and is compiled
514
+ option = jqLite ( select . find ( 'option' ) [ 0 ] ) ;
515
+ expect ( option . hasClass ( 'coyote' ) ) . toBeTruthy ( ) ;
516
+ expect ( option . attr ( 'id' ) ) . toBe ( 'road-runner' ) ;
517
+ expect ( option . attr ( 'custom-attr' ) ) . toBe ( 'custom-attr' ) ;
518
+ } ) ;
519
+ } ) ;
520
+
521
+
448
522
describe ( 'on change' , function ( ) {
449
523
it ( 'should update model on change' , function ( ) {
450
524
createSingleSelect ( ) ;
0 commit comments