Skip to content

Commit 493b0fd

Browse files
committed
Event: Ensure delegation doesn't error on comment nodes
Fixes gh-2055 Close gh-2659
1 parent 769446c commit 493b0fd

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

test/unit/event.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,6 +1852,33 @@ QUnit.test( "delegated event with intermediate DOM manipulation (#13208)", funct
18521852
jQuery( "#anchor2" ).trigger( "click" );
18531853
} );
18541854

1855+
QUnit.test( "ignore comment nodes in event delegation (gh-2055)", function( assert ) {
1856+
assert.expect( 1 );
1857+
1858+
// Test if DOMNodeInserted is supported
1859+
// This is a back-up for when DOMNodeInserted support
1860+
// is eventually removed from browsers
1861+
function test() {
1862+
var ret = false;
1863+
var $fixture = jQuery( "#qunit-fixture" );
1864+
$fixture.on( "DOMNodeInserted", function() {
1865+
ret = true;
1866+
$fixture.off( "DOMNodeInserted" );
1867+
} ).append( "<div></div>" );
1868+
return ret;
1869+
}
1870+
1871+
var $foo = jQuery( "#foo" ).on( "DOMNodeInserted", "[id]", function() {
1872+
assert.ok( true, "No error thrown on comment node" );
1873+
} ),
1874+
$comment = jQuery( document.createComment( "comment" ) )
1875+
.appendTo( $foo.find( "#sap" ) );
1876+
1877+
if ( !test() ) {
1878+
fireNative( $comment[0], "DOMNodeInserted" );
1879+
}
1880+
} );
1881+
18551882
QUnit.test( "stopPropagation() stops directly-bound events on delegated target", function( assert ) {
18561883
assert.expect( 1 );
18571884

0 commit comments

Comments
 (0)