@@ -785,6 +785,37 @@ QUnit.test( "prop('tabindex', value)", function( assert ) {
785785 assert . equal ( clone [ 0 ] . getAttribute ( "tabindex" ) , "1" , "set tabindex on cloned element" ) ;
786786} ) ;
787787
788+ QUnit . test ( "option.prop('selected', true) affects select.selectedIndex (gh-2732)" , function ( assert ) {
789+ assert . expect ( 2 ) ;
790+
791+ function addOptions ( $elem ) {
792+ return $elem . append (
793+ jQuery ( "<option/>" ) . val ( "a" ) . text ( "One" ) ,
794+ jQuery ( "<option/>" ) . val ( "b" ) . text ( "Two" ) ,
795+ jQuery ( "<option/>" ) . val ( "c" ) . text ( "Three" )
796+ )
797+ . find ( "[value=a]" ) . prop ( "selected" , true ) . end ( )
798+ . find ( "[value=c]" ) . prop ( "selected" , true ) . end ( ) ;
799+ }
800+
801+ var $optgroup ,
802+ $select = jQuery ( "<select/>" ) ;
803+
804+ // Check select with options
805+ addOptions ( $select ) . appendTo ( "#qunit-fixture" ) ;
806+ $select . find ( "[value=b]" ) . prop ( "selected" , true ) ;
807+ assert . equal ( $select [ 0 ] . selectedIndex , 1 , "Setting option selected affects selectedIndex" ) ;
808+
809+ $select . empty ( ) ;
810+
811+ // Check select with optgroup
812+ $optgroup = jQuery ( "<optgroup/>" ) ;
813+ addOptions ( $optgroup ) . appendTo ( $select ) ;
814+ $select . find ( "[value=b]" ) . prop ( "selected" , true ) ;
815+
816+ assert . equal ( $select [ 0 ] . selectedIndex , 1 , "Setting option in optgroup selected affects selectedIndex" ) ;
817+ } ) ;
818+
788819QUnit . test ( "removeProp(String)" , function ( assert ) {
789820 assert . expect ( 6 ) ;
790821 var attributeNode = document . createAttribute ( "irrelevant" ) ,
0 commit comments