Permalink
Browse files

Refactored (1.3/1.4) Element.Event.js specs.

1st, prefering Syn.trigger versus Syn[action]. Reduces false positive if
the callback (in Syn) is never called.

2nd, createElement now uses simpler redefine of fireEvent with native
fireEvent.

3rd, updating Runner which drops the simulateEvent.
  • Loading branch information...
1 parent e8f724a commit b35cc9fb7ef8c067a733684378584496a88de3c7 @ibolmo ibolmo committed Nov 27, 2011
Showing with 31 additions and 38 deletions.
  1. +10 −11 1.3client/Element/Element.Event.js
  2. +20 −26 1.4client/Element/Element.Event.js
  3. +1 −1 Runner
@@ -6,11 +6,13 @@ requires: [Core/Element.Event]
provides: [Element.Event.Specs]
...
*/
+
describe('Element.Event', function(){
+ var fragment = document.createDocumentFragment();
// Restore native fireEvent in IE for Syn
var createElement = function(tag, props){
- var el = $(document.createElement(tag));
+ var el = new Element(tag);
el.fireEvent = el._fireEvent;
return el.set(props);
};
@@ -31,11 +33,10 @@ describe('Element.Event', function(){
}
}).inject(document.body);
- Syn.click({}, el, function(){
- alert('click!');
- expect(callback).toHaveBeenCalled();
- el.destroy();
- });
+ Syn.trigger('click', null, el);
+
+ expect(callback).toHaveBeenCalled();
+ el.destroy();
});
// Only run this spec in browsers other than IE6-8 because they can't properly simulate key events
@@ -47,12 +48,10 @@ describe('Element.Event', function(){
callback(event.key);
}).inject(document.body);
- Syn.key('escape', div, function(){
- alert('escape');
- expect(callback).toHaveBeenCalledWith('esc');
- div.destroy();
- });
+ Syn.key('escape', div);
+ expect(callback).toHaveBeenCalledWith('esc');
+ div.destroy();
});
it('should clone events of an element', function(){
@@ -7,14 +7,16 @@ provides: [Element.Event.Specs]
...
*/
-describe('Element.Event + DOMEvent', function(){
+(function(){
+
+// Restore native fireEvent in IE for Syn
+var createElement = function(tag, props){
+ var el = new Element(tag);
+ if (el._fireEvent) el.fireEvent = el._fireEvent;
+ return el.set(props);
+};
- // Restore native fireEvent in IE for Syn
- var createElement = function(tag, props){
- var el = $(document.createElement(tag));
- el.fireEvent = el._fireEvent;
- return el.set(props);
- };
+describe('Element.Event + DOMEvent', function(){
it('Should trigger the click event and prevent the default behavior', function(){
@@ -35,10 +37,10 @@ describe('Element.Event + DOMEvent', function(){
}
}).inject(document.body);
- Syn.click({}, el, function(){
- expect(callback).toHaveBeenCalled();
- el.destroy();
- });
+ Syn.trigger('click', null, el);
+
+ expect(callback).toHaveBeenCalled();
+ el.destroy();
});
@@ -47,16 +49,6 @@ describe('Element.Event + DOMEvent', function(){
describe('Element.Event', function(){
// This is private API. Do not use.
- // Restore native fireEvent in IE for Syn
- var createElement = function(tag, props){
- var el = document.createElement(tag),
- fireEvent = el.fireEvent;
-
- $(el);
- el.fireEvent = fireEvent;
- return el.set(props);
- };
-
it('should pass the name of the custom event to the callbacks', function(){
var callbacks = 0;
var callback = jasmine.createSpy('Element.Event custom');
@@ -81,11 +73,13 @@ describe('Element.Event', function(){
var div = createElement('div').addEvent('customEvent', callback).inject(document.body);
- Syn.click({}, div, function(){
- expect(callback).toHaveBeenCalled();
- div.removeEvent('customEvent', callback).destroy();
- expect(callbacks).toEqual(3);
- });
+ Syn.trigger('click', null, div);
+
+ expect(callback).toHaveBeenCalled();
+ div.removeEvent('customEvent', callback).destroy();
+ expect(callbacks).toEqual(3);
});
});
+
+})();
2 Runner

0 comments on commit b35cc9f

Please sign in to comment.