@@ -38,8 +38,28 @@ describe('select', function() {
3838 } ;
3939
4040 return equals ( expectedValues , actualValues ) ;
41+ } ,
42+
43+ toEqualOption : function ( value , text , label ) {
44+ var errors = [ ] ;
45+ if ( this . actual . attr ( 'value' ) !== value ) {
46+ errors . push ( 'Expected option value "' + this . actual . attr ( 'value' ) + '" to equal "' + value + '"' ) ;
47+ }
48+ if ( text && this . actual . text ( ) !== text ) {
49+ errors . push ( 'Expected option value "' + this . actual . attr ( 'value' ) + '" to equal "' + value + '"' ) ;
50+ }
51+ if ( label && this . actual . attr ( 'label' ) !== label ) {
52+ errors . push ( 'Expected option value "' + this . actual . attr ( 'value' ) + '" to equal "' + value + '"' ) ;
53+ }
54+
55+ this . message = function ( ) {
56+ return errors . join ( '\n' ) ;
57+ } ;
58+
59+ return errors . length === 0 ;
4160 }
4261 } ) ;
62+
4363 } ) ;
4464
4565
@@ -574,9 +594,9 @@ describe('select', function() {
574594
575595 var options = element . find ( 'option' ) ;
576596 expect ( options . length ) . toEqual ( 3 ) ;
577- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value="0">A</option> ') ;
578- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value="1">B</option> ') ;
579- expect ( sortedHtml ( options [ 2 ] ) ) . toEqual ( '<option value="2">C</option> ') ;
597+ expect ( options . eq ( 0 ) ) . toEqualOption ( '0' , 'A ') ;
598+ expect ( options . eq ( 1 ) ) . toEqualOption ( '1' , 'B ') ;
599+ expect ( options . eq ( 2 ) ) . toEqualOption ( '2' , 'C ') ;
580600 } ) ;
581601
582602 it ( 'should render zero as a valid display value' , function ( ) {
@@ -589,9 +609,9 @@ describe('select', function() {
589609
590610 var options = element . find ( 'option' ) ;
591611 expect ( options . length ) . toEqual ( 3 ) ;
592- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value="0">0</option> ') ;
593- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value="1">1</option> ') ;
594- expect ( sortedHtml ( options [ 2 ] ) ) . toEqual ( '<option value="2">2</option> ') ;
612+ expect ( options . eq ( 0 ) ) . toEqualOption ( '0' , '0 ') ;
613+ expect ( options . eq ( 1 ) ) . toEqualOption ( '1' , '1 ') ;
614+ expect ( options . eq ( 2 ) ) . toEqualOption ( '2' , '2 ') ;
595615 } ) ;
596616
597617
@@ -608,9 +628,9 @@ describe('select', function() {
608628
609629 var options = element . find ( 'option' ) ;
610630 expect ( options . length ) . toEqual ( 3 ) ;
611- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value=" blue">blue</option> ') ;
612- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value=" green">green</option> ') ;
613- expect ( sortedHtml ( options [ 2 ] ) ) . toEqual ( '<option value=" red">red</option> ') ;
631+ expect ( options . eq ( 0 ) ) . toEqualOption ( 'blue' , ' blue') ;
632+ expect ( options . eq ( 1 ) ) . toEqualOption ( 'green' , ' green') ;
633+ expect ( options . eq ( 2 ) ) . toEqualOption ( 'red' , ' red') ;
614634 expect ( options [ 2 ] . selected ) . toEqual ( true ) ;
615635
616636 scope . $apply ( function ( ) {
@@ -630,23 +650,23 @@ describe('select', function() {
630650 } ) ;
631651
632652 expect ( element . find ( 'option' ) . length ) . toEqual ( 1 ) ; // because we add special empty option
633- expect ( sortedHtml ( element . find ( 'option' ) [ 0 ] ) ) . toEqual ( '<option value="?"></option> ') ;
653+ expect ( element . find ( 'option' ) ) . toEqualOption ( '?' , ' ') ;
634654
635655 scope . $apply ( function ( ) {
636656 scope . values . push ( { name :'A' } ) ;
637657 scope . selected = scope . values [ 0 ] ;
638658 } ) ;
639659
640660 expect ( element . find ( 'option' ) . length ) . toEqual ( 1 ) ;
641- expect ( sortedHtml ( element . find ( 'option' ) [ 0 ] ) ) . toEqual ( '<option value="0">A</option> ') ;
661+ expect ( element . find ( 'option' ) ) . toEqualOption ( '0' , 'A ') ;
642662
643663 scope . $apply ( function ( ) {
644664 scope . values . push ( { name :'B' } ) ;
645665 } ) ;
646666
647667 expect ( element . find ( 'option' ) . length ) . toEqual ( 2 ) ;
648- expect ( sortedHtml ( element . find ( 'option' ) [ 0 ] ) ) . toEqual ( '<option value="0">A</option> ') ;
649- expect ( sortedHtml ( element . find ( 'option' ) [ 1 ] ) ) . toEqual ( '<option value="1">B</option> ') ;
668+ expect ( element . find ( 'option' ) . eq ( 0 ) ) . toEqualOption ( '0' , 'A ') ;
669+ expect ( element . find ( 'option' ) . eq ( 1 ) ) . toEqualOption ( '1' , 'B ') ;
650670 } ) ;
651671
652672
@@ -665,15 +685,15 @@ describe('select', function() {
665685 } ) ;
666686
667687 expect ( element . find ( 'option' ) . length ) . toEqual ( 2 ) ;
668- expect ( sortedHtml ( element . find ( 'option' ) [ 0 ] ) ) . toEqual ( '<option value="0">A</option> ') ;
669- expect ( sortedHtml ( element . find ( 'option' ) [ 1 ] ) ) . toEqual ( '<option value="1">B</option> ') ;
688+ expect ( element . find ( 'option' ) . eq ( 0 ) ) . toEqualOption ( '0' , 'A ') ;
689+ expect ( element . find ( 'option' ) . eq ( 1 ) ) . toEqualOption ( '1' , 'B ') ;
670690
671691 scope . $apply ( function ( ) {
672692 scope . values . pop ( ) ;
673693 } ) ;
674694
675695 expect ( element . find ( 'option' ) . length ) . toEqual ( 1 ) ;
676- expect ( sortedHtml ( element . find ( 'option' ) [ 0 ] ) ) . toEqual ( '<option value="0">A</option> ') ;
696+ expect ( element . find ( 'option' ) ) . toEqualOption ( '0' , 'A ') ;
677697
678698 scope . $apply ( function ( ) {
679699 scope . values . pop ( ) ;
@@ -725,9 +745,9 @@ describe('select', function() {
725745
726746 var options = element . find ( 'option' ) ;
727747 expect ( options . length ) . toEqual ( 3 ) ;
728- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value="0">B</option> ') ;
729- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value="1">C</option> ') ;
730- expect ( sortedHtml ( options [ 2 ] ) ) . toEqual ( '<option value="2">D</option> ') ;
748+ expect ( options . eq ( 0 ) ) . toEqualOption ( '0' , 'B ') ;
749+ expect ( options . eq ( 1 ) ) . toEqualOption ( '1' , 'C ') ;
750+ expect ( options . eq ( 2 ) ) . toEqualOption ( '2' , 'D ') ;
731751 } ) ;
732752
733753
@@ -771,7 +791,7 @@ describe('select', function() {
771791
772792 var options = element . find ( 'option' ) ;
773793 expect ( options . length ) . toEqual ( 1 ) ;
774- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value=" regularProperty"> visible</option> ') ;
794+ expect ( options . eq ( 0 ) ) . toEqualOption ( ' regularProperty' , ' visible') ;
775795 } ) ;
776796
777797 it ( 'should allow expressions over multiple lines' , function ( ) {
@@ -795,8 +815,8 @@ describe('select', function() {
795815
796816 var options = element . find ( 'option' ) ;
797817 expect ( options . length ) . toEqual ( 3 ) ;
798- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value="0">2</option> ') ;
799- expect ( sortedHtml ( options [ 2 ] ) ) . toEqual ( '<option value="1">3</option> ') ;
818+ expect ( options . eq ( 1 ) ) . toEqualOption ( '0' , '2 ') ;
819+ expect ( options . eq ( 2 ) ) . toEqualOption ( '1' , '3 ') ;
800820 } ) ;
801821
802822 it ( 'should not update selected property of an option element on digest with no change event' ,
@@ -953,8 +973,8 @@ describe('select', function() {
953973
954974 var options = element . find ( 'option' ) ;
955975 expect ( options . length ) . toEqual ( 2 ) ;
956- expect ( sortedHtml ( options [ 0 ] ) ) . toEqual ( '<option value="0">C</option> ') ;
957- expect ( sortedHtml ( options [ 1 ] ) ) . toEqual ( '<option value="1">B</option> ') ;
976+ expect ( options . eq ( 0 ) ) . toEqualOption ( '0' , 'C ') ;
977+ expect ( options . eq ( 1 ) ) . toEqualOption ( '1' , 'B ') ;
958978 } ) ;
959979
960980
0 commit comments