Add another events test and fix from @iirvine
This commit is contained in:
parent
5bbfbd9573
commit
9d4d894450
@ -181,6 +181,27 @@ describe('Events', function() {
|
||||
expect(spy1).not.toHaveBeenCalled();
|
||||
expect(spy2).not.toHaveBeenCalled();
|
||||
});
|
||||
it('doesnt lose track of listeners when removing non existent ones', function () {
|
||||
var obj = new Klass(),
|
||||
spy = jasmine.createSpy(),
|
||||
spy2 = jasmine.createSpy(),
|
||||
foo = {},
|
||||
foo2 = {};
|
||||
|
||||
L.Util.stamp(foo);
|
||||
L.Util.stamp(foo2);
|
||||
|
||||
obj.addEventListener('test', spy, foo2);
|
||||
|
||||
obj.removeEventListener('test', spy, foo); // Decrements test_idx to 0, even though event listener isn't registered with foo's _leaflet_id
|
||||
obj.removeEventListener('test', spy, foo2); // Doesn't get removed
|
||||
|
||||
obj.addEventListener('test', spy2, foo);
|
||||
|
||||
obj.fireEvent('test');
|
||||
|
||||
expect(spy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#on, #off & #fire', function() {
|
||||
|
@ -99,7 +99,7 @@ L.Mixin.Events = {
|
||||
}
|
||||
}
|
||||
|
||||
if (contextId && listeners.length === 0 && events[objKey]) {
|
||||
if (contextId && listeners.length === 0 && events[objKey] && events[objKey][contextId]) {
|
||||
objLenKey = objKey + '_len';
|
||||
delete events[objKey][contextId];
|
||||
events[objLenKey] = (events[objLenKey] || 1) - 1;
|
||||
|
Loading…
Reference in New Issue
Block a user