diff options
author | Scott González <scott.gonzalez@gmail.com> | 2012-06-14 12:33:16 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-06-14 12:33:16 -0400 |
commit | ff39bed57a05ca060033187b8aecebafab357f78 (patch) | |
tree | e82f4c3faa3b5269f0f86e3f186a6f3024ad7466 /tests | |
parent | 00d4beb0ca4a99933bb7e786a1dd50618c180a0b (diff) | |
download | jquery-ui-ff39bed57a05ca060033187b8aecebafab357f78.tar.gz jquery-ui-ff39bed57a05ca060033187b8aecebafab357f78.zip |
Widget: Added _off() for removing event handlers. Fixes #7795 - Widget: _on and _off.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/widget/widget_core.js | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 24ae9c567..abfb0d9de 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -767,6 +767,83 @@ test( "_on() to common element", function() { $( document ).trigger( "customevent" ); }); +test( "_off() - single event", function() { + expect( 3 ); + + $.widget( "ui.testWidget", {} ); + var shouldTriggerWidget, shouldTriggerOther, + element = $( "#widget" ), + widget = element.testWidget().data( "testWidget" ); + widget._on( element, { foo: function() { + ok( shouldTriggerWidget, "foo called from _on" ); + }}); + element.bind( "foo", function() { + ok( shouldTriggerOther, "foo called from bind" ); + }); + shouldTriggerWidget = true; + shouldTriggerOther = true; + element.trigger( "foo" ); + shouldTriggerWidget = false; + widget._off( element, "foo" ); + element.trigger( "foo" ); +}); + +test( "_off() - multiple events", function() { + expect( 6 ); + + $.widget( "ui.testWidget", {} ); + var shouldTriggerWidget, shouldTriggerOther, + element = $( "#widget" ), + widget = element.testWidget().data( "testWidget" ); + widget._on( element, { + foo: function() { + ok( shouldTriggerWidget, "foo called from _on" ); + }, + bar: function() { + ok( shouldTriggerWidget, "bar called from _on" ); + } + }); + element.bind( "foo bar", function( event ) { + ok( shouldTriggerOther, event.type + " called from bind" ); + }); + shouldTriggerWidget = true; + shouldTriggerOther = true; + element.trigger( "foo" ); + element.trigger( "bar" ); + shouldTriggerWidget = false; + widget._off( element, "foo bar" ); + element.trigger( "foo" ); + element.trigger( "bar" ); +}); + +test( "_off() - all events", function() { + expect( 6 ); + + $.widget( "ui.testWidget", {} ); + var shouldTriggerWidget, shouldTriggerOther, + element = $( "#widget" ), + widget = element.testWidget().data( "testWidget" ); + widget._on( element, { + foo: function() { + ok( shouldTriggerWidget, "foo called from _on" ); + }, + bar: function() { + ok( shouldTriggerWidget, "bar called from _on" ); + } + }); + element.bind( "foo bar", function( event ) { + ok( shouldTriggerOther, event.type + " called from bind" ); + }); + shouldTriggerWidget = true; + shouldTriggerOther = true; + element.trigger( "foo" ); + element.trigger( "bar" ); + shouldTriggerWidget = false; + widget._off( element ); + element.trigger( "foo" ); + element.trigger( "bar" ); +}); + test( "._hoverable()", function() { $.widget( "ui.testWidget", { _create: function() { |