diff --git a/bower.json b/bower.json index 7be4b0d..cecb2d8 100644 --- a/bower.json +++ b/bower.json @@ -24,7 +24,7 @@ "css" ], "dependencies": { - "events-amd": "1.1.0" + "events-amd": "1.1.2" }, "devDependencies": { "async-define": "elo7/async-define" diff --git a/test/docTest.js.html b/test/docTest.js.html index dfc30a8..aeabf89 100644 --- a/test/docTest.js.html +++ b/test/docTest.js.html @@ -262,6 +262,10 @@ $('#off-button').off('click', 'named-1'); fireEvent($('#off-button').first(), 'click'); assert.equal( $('#off-count').val(), 3); + + $('#off-button').off('click', 'named-2'); + fireEvent($('#off-button').first(), 'click'); + assert.equal( $('#off-count').val(), 3); }); it('should select text correctly', function(){ @@ -510,6 +514,47 @@ $(".insert-filter").insertAfter(reference); }, /without parent/); }); + + it("should not throw error when off'ing an event that was not registered yet", function() { + var count = 0; + $('#off-count').val(count); + + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 0); + + $('#off-button').off('click'); + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 0); + + $('#off-button').off('click', 'someName'); + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 0); + }); + + it("should not remove unnamed listeners when removing named listeners, even if they don't exist", function() { + var count = 0; + $('#off-button').on('click', function(){ + $('#off-count').val(++count); + }); + + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 1); + + $('#off-button').off('click', 'someName'); + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 2); + + $('#off-button').on('click', function(){ + $('#off-count').val(++count); + }, 'someName'); + + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 4); + + $('#off-button').off('click', 'someName'); + fireEvent($('#off-button').first(), 'click'); + assert.equal($('#off-count').val(), 5); + }); }); });