From ac5b9055f6d7224e5e8e49941c0fc9cb16c64a7e Mon Sep 17 00:00:00 2001 From: Pawel Kozlowski Date: Sat, 3 Aug 2013 17:57:37 +0200 Subject: [PATCH] fix(jqLite): forgive unregistration of a non-registered handler --- src/jqLite.js | 2 +- test/jqLiteSpec.js | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/jqLite.js b/src/jqLite.js index fc8fba07..1bcd9224 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -205,7 +205,7 @@ function JQLiteUnbind(element, type, fn) { removeEventListenerFn(element, type, events[type]); delete events[type]; } else { - arrayRemove(events[type], fn); + arrayRemove(events[type] || [], fn); } } } diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 6aafd1f8..5b9a122c 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -843,6 +843,12 @@ describe('jqLite', function() { aElem.unbind('click', function() {}); }); + it('should do nothing when a specific listener was not registered', function () { + var aElem = jqLite(a); + aElem.bind('click', function() {}); + + aElem.unbind('mouseenter', function() {}); + }); it('should deregister all listeners', function() { var aElem = jqLite(a),