diff --git a/tests/unit/selectmenu/selectmenu_events.js b/tests/unit/selectmenu/selectmenu_events.js index 4d98c9dde..4881e0bff 100644 --- a/tests/unit/selectmenu/selectmenu_events.js +++ b/tests/unit/selectmenu/selectmenu_events.js @@ -6,11 +6,12 @@ module( "selectmenu: events", { } }); -test( "change", function () { +asyncTest( "change", function () { expect( 5 ); var that = this, - optionIndex = 1; + optionIndex = 1, + button, menu, options; this.element.selectmenu({ change: function ( event, ui ) { @@ -22,12 +23,17 @@ test( "change", function () { } }); - var button = this.element.selectmenu( "widget" ), - menu = this.element.selectmenu( "menuWidget" ).parent(), - options = this.element.find( "option" ); + button = this.element.selectmenu( "widget" ); + menu = this.element.selectmenu( "menuWidget" ).parent(); + options = this.element.find( "option" ); - button.simulate( "focus" ).simulate( "click" ); - menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" ); + button.simulate( "focus" ); + + setTimeout(function() { + button.simulate( "click" ); + menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" ); + start(); + }, 1 ); }); @@ -40,20 +46,21 @@ test( "close", function () { equal( event.type, "selectmenuclose", "event type set to selectmenuclose" ); } }); - + this.element.selectmenu( "open" ).selectmenu( "close" ); - + this.element.selectmenu( "open" ); $( "body" ).simulate( "click" ); }); -test( "focus", function () { +asyncTest( "focus", function () { expect( 12 ); - var button, menu, links, + var that = this, optionIndex = this.element[ 0 ].selectedIndex + 1, - options = this.element.find( "option" ); + options = this.element.find( "option" ), + button, menu, links; this.element.selectmenu({ focus: function ( event, ui ) { @@ -67,19 +74,22 @@ test( "focus", function () { button = this.element.selectmenu( "widget" ), menu = this.element.selectmenu( "menuWidget" ); - button - .simulate( "focus" ) - .simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + button.simulate( "focus" ) - button.simulate( "click" ); - links = menu.find( "li.ui-menu-item a" ); - optionIndex = 0; - links.eq( optionIndex ).simulate( "mouseover" ); - optionIndex += 1; - links.eq( optionIndex ).simulate( "mouseover" ); + setTimeout(function() { + button.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); - // this tests for unwanted, additional focus event on close - this.element.selectmenu( "close" ); + button.simulate( "click" ); + links = menu.find( "li.ui-menu-item a" ); + optionIndex = 0; + links.eq( optionIndex ).simulate( "mouseover" ); + optionIndex += 1; + links.eq( optionIndex ).simulate( "mouseover" ); + + // this tests for unwanted, additional focus event on close + that.element.selectmenu( "close" ); + start(); + }, 1 ); }); @@ -97,7 +107,7 @@ test( "open", function () { }); -test( "select", function () { +asyncTest( "select", function () { expect( 4 ); this.element.selectmenu({ @@ -114,8 +124,13 @@ test( "select", function () { options = this.element.find( "option" ), optionIndex = 1; - button.simulate( "focus" ).simulate( "click" ); - menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" ); + button.simulate( "focus" ); + + setTimeout(function() { + button.simulate( "click" ); + menu.find( "a" ).eq( optionIndex ).simulate( "mouseover" ).simulate( "click" ); + start(); + }, 1 ); }); })(jQuery); diff --git a/tests/unit/selectmenu/selectmenu_methods.js b/tests/unit/selectmenu/selectmenu_methods.js index 96efa9a6a..05f2404d1 100644 --- a/tests/unit/selectmenu/selectmenu_methods.js +++ b/tests/unit/selectmenu/selectmenu_methods.js @@ -68,7 +68,7 @@ test( "refresh - structure", function () { equal( element.find( "option" ).first().text(), menu.find( "li" ).not( ".ui-selectmenu-optgroup" ).first().text(), "changed item" ); }); -test( "refresh - change selected option", function () { +asyncTest( "refresh - change selected option", function () { expect( 3 ); var element = $( "#speed" ).selectmenu(), @@ -78,13 +78,16 @@ test( "refresh - change selected option", function () { button.simulate( "focus" ); - equal( element.find( "option:selected" ).text(), button.text(), "button text after focus" ); + setTimeout(function() { + equal( element.find( "option:selected" ).text(), button.text(), "button text after focus" ); - element.find( "option" ).eq( 2 ).removeAttr( "selected" ); - element.find( "option" ).eq( 0 ).attr( "selected", "selected" ); - element.selectmenu( "refresh" ); + element[ 0 ].selectedIndex = 0 + element.selectmenu( "refresh" ); - equal( element.find( "option:selected" ).text(), button.text(), "button text after changing selected option" ); + equal( element.find( "option:selected" ).text(), button.text(), "button text after changing selected option" ); + + start(); + }, 1 ); });