aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTimmy Willison <timmywillisn@gmail.com>2015-10-18 12:24:01 -0400
committerTimmy Willison <timmywillisn@gmail.com>2015-11-04 18:09:33 -0500
commit493b0fd7f51054345abe981270bd7839825f79dd (patch)
treea9b412c72fe3d136db0153958dd55ad3db402e4a
parent769446c69775f6c44e35cee1bcdeccafba51be7b (diff)
downloadjquery-493b0fd7f51054345abe981270bd7839825f79dd.tar.gz
jquery-493b0fd7f51054345abe981270bd7839825f79dd.zip
Event: Ensure delegation doesn't error on comment nodes
Fixes gh-2055 Close gh-2659
-rw-r--r--test/unit/event.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/unit/event.js b/test/unit/event.js
index 479f805db..26d972a5b 100644
--- a/test/unit/event.js
+++ b/test/unit/event.js
@@ -1852,6 +1852,33 @@ QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", funct
jQuery( "#anchor2" ).trigger( "click" );
} );
+QUnit.test( "ignore comment nodes in event delegation (gh-2055)", function( assert ) {
+ assert.expect( 1 );
+
+ // Test if DOMNodeInserted is supported
+ // This is a back-up for when DOMNodeInserted support
+ // is eventually removed from browsers
+ function test() {
+ var ret = false;
+ var $fixture = jQuery( "#qunit-fixture" );
+ $fixture.on( "DOMNodeInserted", function() {
+ ret = true;
+ $fixture.off( "DOMNodeInserted" );
+ } ).append( "<div></div>" );
+ return ret;
+ }
+
+ var $foo = jQuery( "#foo" ).on( "DOMNodeInserted", "[id]", function() {
+ assert.ok( true, "No error thrown on comment node" );
+ } ),
+ $comment = jQuery( document.createComment( "comment" ) )
+ .appendTo( $foo.find( "#sap" ) );
+
+ if ( !test() ) {
+ fireNative( $comment[0], "DOMNodeInserted" );
+ }
+} );
+
QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
assert.expect( 1 );