Script and makefile adjustments for updating extlib
[larjonas-mediagoblin.git] / extlib / leaflet / spec / suites / core / EventsSpec.js
blobbe143866891499e26d210542218f85ff73949377
1 describe('Events', function() {
2 var Klass;
4 beforeEach(function() {
5 Klass = L.Class.extend({
6 includes: L.Mixin.Events
7 });
8 });
10 describe('#fireEvent', function() {
12 it('should fire all listeners added through #addEventListener', function() {
13 var obj = new Klass(),
14 spy = jasmine.createSpy(),
15 spy2 = jasmine.createSpy(),
16 spy3 = jasmine.createSpy();
18 obj.addEventListener('test', spy);
19 obj.addEventListener('test', spy2);
20 obj.addEventListener('other', spy3);
22 expect(spy).not.toHaveBeenCalled();
23 expect(spy2).not.toHaveBeenCalled();
24 expect(spy3).not.toHaveBeenCalled();
26 obj.fireEvent('test');
28 expect(spy).toHaveBeenCalled();
29 expect(spy2).toHaveBeenCalled();
30 expect(spy3).not.toHaveBeenCalled();
31 });
33 it('should provide event object to listeners and execute them in the right context', function() {
34 var obj = new Klass(),
35 obj2 = new Klass(),
36 foo = {};
38 function listener1(e) {
39 expect(e.type).toEqual('test');
40 expect(e.target).toEqual(obj);
41 expect(this).toEqual(obj);
42 expect(e.bar).toEqual(3);
45 function listener2(e) {
46 expect(e.target).toEqual(obj2);
47 expect(this).toEqual(foo);
50 obj.addEventListener('test', listener1);
51 obj2.addEventListener('test', listener2, foo);
53 obj.fireEvent('test', {bar: 3});
54 });
56 it('should not call listeners removed through #removeEventListener', function() {
57 var obj = new Klass(),
58 spy = jasmine.createSpy();
60 obj.addEventListener('test', spy);
61 obj.removeEventListener('test', spy);
63 obj.fireEvent('test');
65 expect(spy).not.toHaveBeenCalled();
66 });
67 });
69 describe('#on, #off & #fire', function() {
71 it('should work like #addEventListener && #removeEventListener', function() {
72 var obj = new Klass(),
73 spy = jasmine.createSpy();
75 obj.on('test', spy);
76 obj.fire('test');
78 expect(spy).toHaveBeenCalled();
80 obj.off('test', spy);
81 obj.fireEvent('test');
83 expect(spy.callCount).toBeLessThan(2);
84 });
86 it('should not override existing methods with the same name', function() {
87 var spy1 = jasmine.createSpy(),
88 spy2 = jasmine.createSpy(),
89 spy3 = jasmine.createSpy();
91 var Klass2 = L.Class.extend({
92 includes: L.Mixin.Events,
93 on: spy1,
94 off: spy2,
95 fire: spy3
96 });
98 var obj = new Klass2();
100 obj.on();
101 expect(spy1).toHaveBeenCalled();
103 obj.off();
104 expect(spy2).toHaveBeenCalled();
106 obj.fire();
107 expect(spy3).toHaveBeenCalled();