merge: In README, correct path to point to mootools.
[mootools.git] / Specs / Element / Element.Delegation.js
bloba39b5395e02203985a3328dfd051ea8944ed1b9d
1 /*
2 ---
3 name: Element.Delegation
4 requires: ~
5 provides: ~
6 ...
7 */
9 describe('Element.Delegation', function(){
11         describe('fireEvent', function(){
13                 it('should fire the added `click:relay(a)` function with fireEvent', function(){
15                         var a = new Element('a[text=Hello World]'), result, self;
16                         var div = new Element('div').inject(document.body).adopt(a).addEvent('click:relay(a)', function(){
17                                 result = arguments[1];
18                                 self = this;
19                         }).fireEvent('click:relay(a)', [null, a]);
21                         expect(result).toEqual(a);
22                         expect(self).toEqual(div);
24                         div.destroy();
26                 });
28                 it('Should fire click events through fireEvent and delegate when a target is passed as argument', function(){
30                         var a = new Element('a[text="Hello World"]'), result, self;
31                         var div = new Element('div').inject(document.body).adopt(a).addEvent('click:relay(a)', function(){
32                                 result = arguments[1];
33                                 self = this;
34                         }).fireEvent('click', [null, a]);
36                         expect(result).toEqual(a);
37                         expect(self).toEqual(a);
39                         div.destroy();
41                 });
43                 it('Should not fire click events through fireEvent when added as delegated events without an target', function(){
45                         var spy = jasmine.createSpy('click');
46                         var a = new Element('a[text="Hello World"]');
47                         var div = new Element('div').inject(document.body).adopt(a).addEvent('click:relay(a)', spy).fireEvent('click');
49                         expect(spy).not.toHaveBeenCalled();
51                         div.destroy();
53                 });
55         });
57 });