diff --git a/jquery.simulate.js b/jquery.simulate.js index 4ac556a..eeb5624 100644 --- a/jquery.simulate.js +++ b/jquery.simulate.js @@ -201,7 +201,9 @@ $.extend( $.simulate.prototype, { }, dispatchEvent: function( elem, type, event ) { - if ( elem.dispatchEvent ) { + if ( elem[ type ] ) { + elem[ type ](); + } else if ( elem.dispatchEvent ) { elem.dispatchEvent( event ); } else if ( elem.fireEvent ) { elem.fireEvent( "on" + type, event ); diff --git a/test/index.html b/test/index.html index 3e27a25..88ea915 100644 --- a/test/index.html +++ b/test/index.html @@ -19,5 +19,10 @@

    + \ No newline at end of file diff --git a/test/testinit.css b/test/testinit.css index 2748790..453d0d0 100644 --- a/test/testinit.css +++ b/test/testinit.css @@ -7,4 +7,9 @@ margin: 0; padding: 0; border: none; +} + +.hidden { + position: absolute; + left: -9999px; } \ No newline at end of file diff --git a/test/unit/simulate.js b/test/unit/simulate.js index 6c88506..07d246a 100644 --- a/test/unit/simulate.js +++ b/test/unit/simulate.js @@ -1,5 +1,30 @@ (function() { +module( "mouse events" ); + +test( "click on checkbox triggers change", function() { + var input = $( "#radiocheckbox-3" ), + checked = input.prop( "checked" ); + + input.simulate( "click" ); + + notEqual( checked, input.prop( "checked" ), "checkbox state changed" ); +}); + +test( "click on radio triggers change", function() { + var firstRadio = $( "#radiocheckbox-1" ), + secondRadio = $( "#radiocheckbox-2" ), + checked = firstRadio.prop( "checked" ); + + if ( checked ) { + secondRadio.simulate( "click" ); + } else { + firstRadio.simulate( "click" ); + } + + notEqual( checked, firstRadio.prop( "checked" ), "radio state changed" ); +}); + var key = jQuery.simulate.keyCode, keyEvents = [ "keydown", "keyup", "keypress" ], i = 0;