@@ -405,6 +405,39 @@ describe('select', function() {
405
405
expect ( element ) . toEqualSelect ( [ '? string:r2d2 ?' ] ) ;
406
406
expect ( scope . robot ) . toBe ( 'r2d2' ) ;
407
407
} ) ;
408
+
409
+ describe ( 'selectController.hasOption' , function ( ) {
410
+ it ( 'should return true for options added via ngOptions' , function ( ) {
411
+ scope . robots = [
412
+ { key : 1 , value : 'c3p0' } ,
413
+ { key : 2 , value : 'r2d2' }
414
+ ] ;
415
+ scope . robot = 'r2d2' ;
416
+
417
+ compile ( '<select ng-model="robot" ' +
418
+ 'ng-options="item.key as item.value for item in robots">' +
419
+ '</select>' ) ;
420
+
421
+ var selectCtrl = element . data ( ) . $selectController ;
422
+
423
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
424
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
425
+
426
+ scope . $apply ( function ( ) {
427
+ scope . robots . pop ( ) ;
428
+ } ) ;
429
+
430
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
431
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
432
+
433
+ scope . $apply ( function ( ) {
434
+ scope . robots . push ( { key : 2 , value : 'r2d2' } ) ;
435
+ } ) ;
436
+
437
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
438
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
439
+ } ) ;
440
+ } ) ;
408
441
} ) ;
409
442
} ) ;
410
443
} ) ;
@@ -481,6 +514,39 @@ describe('select', function() {
481
514
expect ( element ) . toBeValid ( ) ;
482
515
expect ( element ) . toBeDirty ( ) ;
483
516
} ) ;
517
+
518
+ describe ( 'selectController.hasOption' , function ( ) {
519
+ it ( 'should return true for options added via ngOptions' , function ( ) {
520
+ scope . robots = [
521
+ { key : 1 , value : 'c3p0' } ,
522
+ { key : 2 , value : 'r2d2' }
523
+ ] ;
524
+ scope . robot = 'r2d2' ;
525
+
526
+ compile ( '<select ng-model="robot" multiple ' +
527
+ 'ng-options="item.key as item.value for item in robots">' +
528
+ '</select>' ) ;
529
+
530
+ var selectCtrl = element . data ( ) . $selectController ;
531
+
532
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
533
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
534
+
535
+ scope . $apply ( function ( ) {
536
+ scope . robots . pop ( ) ;
537
+ } ) ;
538
+
539
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
540
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
541
+
542
+ scope . $apply ( function ( ) {
543
+ scope . robots . push ( { key : 2 , value : 'r2d2' } ) ;
544
+ } ) ;
545
+
546
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
547
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
548
+ } ) ;
549
+ } ) ;
484
550
} ) ;
485
551
486
552
0 commit comments