From ab59cc6c44705b1244a77eba999d736f9eb3c6ae 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 8a8a28e8d2d4..775fef512a67 100644 --- a/src/jqLite.js +++ b/src/jqLite.js @@ -212,7 +212,7 @@ function JQLiteOff(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 e74c09a54731..3648cda487d7 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -890,6 +890,12 @@ describe('jqLite', function() { aElem.off('click', function() {}); }); + it('should do nothing when a specific listener was not registered', function () { + var aElem = jqLite(a); + aElem.on('click', function() {}); + + aElem.off('mouseenter', function() {}); + }); it('should deregister all listeners', function() { var aElem = jqLite(a),