Permalink
Browse files

Event: Fix chaining .on() with null handlers

Fixes gh-2846
  • Loading branch information...
dwilson6 authored and timmywil committed Jan 14, 2016
1 parent 780cac8 commit 17f0e26ad9eba67ab274d12274cf7c23c8c688fd
Showing with 24 additions and 0 deletions.
  1. +2 −0 src/event.js
  2. +22 −0 test/unit/event.js
View
@@ -70,6 +70,8 @@ function on( elem, types, selector, data, fn, one ) {
}
if ( fn === false ) {
fn = returnFalse;
} else if ( !fn ) {
return elem;
}
if ( one === 1 ) {
View
@@ -5,6 +5,28 @@ QUnit.module( "event", {
teardown: moduleTeardown
} );
QUnit.test( "null or undefined handler", function( assert ) {
assert.expect( 4 );
// Supports Fixes bug #7229
try {
jQuery( "#firstp" ).on( "click", null );
assert.ok( true, "Passing a null handler will not throw an exception" );
} catch ( e ) {}
try {
jQuery( "#firstp" ).on( "click", undefined );
assert.ok( true, "Passing an undefined handler will not throw an exception" );
} catch ( e ) {}
var expectedElem = jQuery( "#firstp" );
var actualElem = expectedElem.on( "click", null );
assert.equal(actualElem, expectedElem, "Passing a null handler should return the original element");
actualElem = expectedElem.on( "click", undefined );
assert.equal(actualElem, expectedElem, "Passing a null handler should return the original element");
} );
QUnit.test( "on() with non-null,defined data", function( assert ) {
assert.expect( 2 );

0 comments on commit 17f0e26

Please sign in to comment.