3 name: Element.Delegation
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];
19 }).fireEvent('click:relay(a)', [null, a]);
21 expect(result).toEqual(a);
22 expect(self).toEqual(div);
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];
34 }).fireEvent('click', [null, a]);
36 expect(result).toEqual(a);
37 expect(self).toEqual(a);
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();