@@ -378,6 +378,39 @@ describe('select', function() {
378
378
expect ( element ) . toEqualSelect ( [ '? string:r2d2 ?' ] ) ;
379
379
expect ( scope . robot ) . toBe ( 'r2d2' ) ;
380
380
} ) ;
381
+
382
+ describe ( 'selectController.hasOption' , function ( ) {
383
+ it ( 'should return true for options added via ngOptions' , function ( ) {
384
+ scope . robots = [
385
+ { key : 1 , value : 'c3p0' } ,
386
+ { key : 2 , value : 'r2d2' }
387
+ ] ;
388
+ scope . robot = 'r2d2' ;
389
+
390
+ compile ( '<select ng-model="robot" ' +
391
+ 'ng-options="item.key as item.value for item in robots">' +
392
+ '</select>' ) ;
393
+
394
+ var selectCtrl = element . data ( ) . $selectController ;
395
+
396
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
397
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
398
+
399
+ scope . $apply ( function ( ) {
400
+ scope . robots . pop ( ) ;
401
+ } ) ;
402
+
403
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
404
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
405
+
406
+ scope . $apply ( function ( ) {
407
+ scope . robots . push ( { key : 2 , value : 'r2d2' } ) ;
408
+ } ) ;
409
+
410
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
411
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
412
+ } ) ;
413
+ } ) ;
381
414
} ) ;
382
415
} ) ;
383
416
} ) ;
@@ -454,6 +487,39 @@ describe('select', function() {
454
487
expect ( element ) . toBeValid ( ) ;
455
488
expect ( element ) . toBeDirty ( ) ;
456
489
} ) ;
490
+
491
+ describe ( 'selectController.hasOption' , function ( ) {
492
+ it ( 'should return true for options added via ngOptions' , function ( ) {
493
+ scope . robots = [
494
+ { key : 1 , value : 'c3p0' } ,
495
+ { key : 2 , value : 'r2d2' }
496
+ ] ;
497
+ scope . robot = 'r2d2' ;
498
+
499
+ compile ( '<select ng-model="robot" multiple ' +
500
+ 'ng-options="item.key as item.value for item in robots">' +
501
+ '</select>' ) ;
502
+
503
+ var selectCtrl = element . data ( ) . $selectController ;
504
+
505
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
506
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
507
+
508
+ scope . $apply ( function ( ) {
509
+ scope . robots . pop ( ) ;
510
+ } ) ;
511
+
512
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
513
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( false ) ;
514
+
515
+ scope . $apply ( function ( ) {
516
+ scope . robots . push ( { key : 2 , value : 'r2d2' } ) ;
517
+ } ) ;
518
+
519
+ expect ( selectCtrl . hasOption ( 'c3p0' ) ) . toBe ( true ) ;
520
+ expect ( selectCtrl . hasOption ( 'r2d2' ) ) . toBe ( true ) ;
521
+ } ) ;
522
+ } ) ;
457
523
} ) ;
458
524
459
525
0 commit comments