Skip to content

Commit

Permalink
Merge pull request #41 from elo7/lenient-off
Browse files Browse the repository at this point in the history
[lenient-off] Fix error when trying to off an event that has not been registered
  • Loading branch information
erikatakahara authored Jan 18, 2017
2 parents 5feaa1e + 5d34b39 commit e0d5ca5
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"css"
],
"dependencies": {
"events-amd": "1.1.0"
"events-amd": "1.1.2"
},
"devDependencies": {
"async-define": "elo7/async-define"
Expand Down
45 changes: 45 additions & 0 deletions test/docTest.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down Expand Up @@ -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);
});
});
});
</script>
Expand Down

0 comments on commit e0d5ca5

Please sign in to comment.