diff options
author | Timmy Willison <timmywillisn@gmail.com> | 2016-01-15 16:48:52 -0500 |
---|---|---|
committer | Timmy Willison <timmywillisn@gmail.com> | 2016-01-19 11:36:47 -0500 |
commit | 780cac802b32a0125c467a644b3803be378ae6ab (patch) | |
tree | 5aeee2370206a4a455b629abcf182115b3857cf4 /test | |
parent | fe05cf37ffd4795988f9b2343df2182e108728ca (diff) | |
download | jquery-780cac802b32a0125c467a644b3803be378ae6ab.tar.gz jquery-780cac802b32a0125c467a644b3803be378ae6ab.zip |
Attributes: fix setting selected on an option in IE<=11
Fixes gh-2732
Close gh-2840
Diffstat (limited to 'test')
-rw-r--r-- | test/unit/attributes.js | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/unit/attributes.js b/test/unit/attributes.js index 7f92d3505..f691e31ee 100644 --- a/test/unit/attributes.js +++ b/test/unit/attributes.js @@ -796,6 +796,37 @@ QUnit.test( "prop('tabindex', value)", function( assert ) { assert.equal( clone[ 0 ].getAttribute( "tabindex" ), "1", "set tabindex on cloned element" ); } ); +QUnit.test( "option.prop('selected', true) affects select.selectedIndex (gh-2732)", function( assert ) { + assert.expect( 2 ); + + function addOptions( $elem ) { + return $elem.append( + jQuery( "<option/>" ).val( "a" ).text( "One" ), + jQuery( "<option/>" ).val( "b" ).text( "Two" ), + jQuery( "<option/>" ).val( "c" ).text( "Three" ) + ) + .find( "[value=a]" ).prop( "selected", true ).end() + .find( "[value=c]" ).prop( "selected", true ).end(); + } + + var $optgroup, + $select = jQuery( "<select/>" ); + + // Check select with options + addOptions( $select ).appendTo( "#qunit-fixture" ); + $select.find( "[value=b]" ).prop( "selected", true ); + assert.equal( $select[ 0 ].selectedIndex, 1, "Setting option selected affects selectedIndex" ); + + $select.empty(); + + // Check select with optgroup + $optgroup = jQuery( "<optgroup/>" ); + addOptions( $optgroup ).appendTo( $select ); + $select.find( "[value=b]" ).prop( "selected", true ); + + assert.equal( $select[ 0 ].selectedIndex, 1, "Setting option in optgroup selected affects selectedIndex" ); +} ); + QUnit.test( "removeProp(String)", function( assert ) { assert.expect( 6 ); var attributeNode = document.createAttribute( "irrelevant" ), |