aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRick Waldron <waldron.rick@gmail.com>2011-09-20 12:44:49 -0400
committerRick Waldron <waldron.rick@gmail.com>2011-09-20 12:44:49 -0400
commit92a80cbd057c06e259a06bb40a85e921ad5aec6a (patch)
treef8b2df93093fbea2f921d4a16073e997a7dfb6eb /test
parent26898f0bc593f1a2b7d5f2cc4e86f173bf9cf17c (diff)
downloadjquery-92a80cbd057c06e259a06bb40a85e921ad5aec6a.tar.gz
jquery-92a80cbd057c06e259a06bb40a85e921ad5aec6a.zip
Adds implementation tests for jQuery.event.propHooks #8789
Diffstat (limited to 'test')
-rw-r--r--test/unit/event.js71
1 files changed, 65 insertions, 6 deletions
diff --git a/test/unit/event.js b/test/unit/event.js
index a7a989a56..7efef7522 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -54,7 +54,7 @@ test("Handler changes and .trigger() order", function() {
markup.find( "b" ).trigger( "click" );
equals( path, "p div body html ", "Delivered all events" )
-
+
markup.remove();
});
*/
@@ -2332,13 +2332,13 @@ test(".on and .off", function() {
// We should have removed all the event handlers ... kinda hacky way to check this
var data = jQuery.data[ jQuery( "#onandoff" )[0].expando ] || {};
equals( data.events, undefined, "no events left" );
-
+
jQuery("#onandoff").remove();
});
test("delegated events quickIs", function() {
expect(23);
- var markup = jQuery(
+ var markup = jQuery(
'<div>'+
'<p class="D">'+
'dead<b devo="cool">beat</b>club'+
@@ -2349,12 +2349,12 @@ test("delegated events quickIs", function() {
'</div>'
),
str,
- check = function(el, expect){
+ check = function(el, expect){
str = "";
markup.find( el ).trigger( "blink" );
equals( str, expect, "On " + el );
},
- func = function(e){
+ func = function(e){
var tag = this.nodeName.toLowerCase();
str += (str && " ") + tag + "|" + e.handleObj.selector;
ok( e.handleObj.quick, "Selector "+ e.handleObj.selector + " on " + tag + " is a quickIs case" );
@@ -2379,7 +2379,7 @@ test("delegated events quickIs", function() {
check( "p", "p|.D p|:first-child" );
check( "b", "b|[devo=cool] p|.D p|:first-child" );
check( "em", "em|em q|#famous em|em em|em:empty em|em:last-child q|#famous" );
-
+
markup.find( "b" ).attr( "devo", "NO" );
check( "b", "b|[devo='NO'] p|.D p|:first-child" );
@@ -2460,6 +2460,65 @@ test("delegated events quickIs", function() {
})();
+test("jQuery.event.propHooks", function() {
+ expect( 1 );
+ ok( jQuery.event.propHooks, "jQuery.event.propHooks exists" );
+});
+
+test("jQuery.event.propHooks as function", function() {
+
+ expect( 2 );
+
+ jQuery( "<div id='hook-fixture'></div>" ).appendTo( "#qunit-fixture" );
+
+ var $fixture = jQuery( "#hook-fixture" );
+
+ // Does not exist
+ $fixture.bind( "click", function( event ) {
+ ok( !("propC" in event), "event.propC Does not exist" );
+ }).trigger( "click" );
+
+ $fixture.unbind( "click" );
+
+ // Store as function
+ jQuery.event.propHooks[ "custom" ] = function( event ) {
+ // receives the event object for processing
+ event.propC = true;
+ return event;
+ };
+
+ $fixture.bind( "custom", function( event ) {
+ ok( event.propC, "event.propC exists" );
+ }).trigger( "custom" );
+});
+
+test("jQuery.event.propHooks usecase", function() {
+
+ expect( 3 );
+
+ jQuery( "<div id='hook-fixture'></div>" ).appendTo( "#qunit-fixture" );
+
+ var $fixture = jQuery( "#hook-fixture" );
+
+ $fixture.bind( "fakedrop", function( event ) {
+ ok( !("dataTransfer" in event), "event.dataTransfer is not available" );
+ }).trigger( "fakedrop" );
+
+ $fixture.unbind( "fakedrop" );
+
+ jQuery.event.propHooks[ "fakedrop" ] = function( event ) {
+ event.dataTransfer = "some val";
+ return event;
+ };
+
+ $fixture.bind( "fakedrop", function( event ) {
+ ok( ("dataTransfer" in event), "event.dataTransfer exists, just copied" );
+ equal( event.dataTransfer, "some val", "event.dataTransfer equal 'some val'" );
+ }).trigger( "fakedrop" );
+
+ $fixture.unbind( "fakedrop" );
+});
+
/*
test("event properties", function() {
stop();