@@ -405,6 +405,39 @@ describe('select', function() {
405405          expect ( element ) . toEqualSelect ( [ '? string:r2d2 ?' ] ) ; 
406406          expect ( scope . robot ) . toBe ( 'r2d2' ) ; 
407407        } ) ; 
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+         } ) ; 
408441      } ) ; 
409442    } ) ; 
410443  } ) ; 
@@ -481,6 +514,39 @@ describe('select', function() {
481514      expect ( element ) . toBeValid ( ) ; 
482515      expect ( element ) . toBeDirty ( ) ; 
483516    } ) ; 
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+     } ) ; 
484550  } ) ; 
485551
486552
0 commit comments