@@ -796,6 +796,37 @@ QUnit.test( "prop('tabindex', value)", function( assert ) {
796796 assert . equal ( clone [ 0 ] . getAttribute ( "tabindex" ) , "1" , "set tabindex on cloned element" ) ;
797797} ) ;
798798
799+ QUnit . test ( "option.prop('selected', true) affects select.selectedIndex (gh-2732)" , function ( assert ) {
800+ assert . expect ( 2 ) ;
801+
802+ function addOptions ( $elem ) {
803+ return $elem . append (
804+ jQuery ( "<option/>" ) . val ( "a" ) . text ( "One" ) ,
805+ jQuery ( "<option/>" ) . val ( "b" ) . text ( "Two" ) ,
806+ jQuery ( "<option/>" ) . val ( "c" ) . text ( "Three" )
807+ )
808+ . find ( "[value=a]" ) . prop ( "selected" , true ) . end ( )
809+ . find ( "[value=c]" ) . prop ( "selected" , true ) . end ( ) ;
810+ }
811+
812+ var $optgroup ,
813+ $select = jQuery ( "<select/>" ) ;
814+
815+ // Check select with options
816+ addOptions ( $select ) . appendTo ( "#qunit-fixture" ) ;
817+ $select . find ( "[value=b]" ) . prop ( "selected" , true ) ;
818+ assert . equal ( $select [ 0 ] . selectedIndex , 1 , "Setting option selected affects selectedIndex" ) ;
819+
820+ $select . empty ( ) ;
821+
822+ // Check select with optgroup
823+ $optgroup = jQuery ( "<optgroup/>" ) ;
824+ addOptions ( $optgroup ) . appendTo ( $select ) ;
825+ $select . find ( "[value=b]" ) . prop ( "selected" , true ) ;
826+
827+ assert . equal ( $select [ 0 ] . selectedIndex , 1 , "Setting option in optgroup selected affects selectedIndex" ) ;
828+ } ) ;
829+
799830QUnit . test ( "removeProp(String)" , function ( assert ) {
800831 assert . expect ( 6 ) ;
801832 var attributeNode = document . createAttribute ( "irrelevant" ) ,
0 commit comments