Skip to content

Commit

Permalink
All green. Removed simulateEvent usage. Added names to each spy.
Browse files Browse the repository at this point in the history
IE8 had problems with the native fireEvent being trampled by
Element.Prototype. This commit assumes that an element has access to the
native fireEvent in _fireEvent.

simulateEvent is no longer necessary, and adding a name to each spy
helps with debugging jasmine reports.
  • Loading branch information
ibolmo committed Nov 25, 2011
1 parent 2fb8412 commit e8f724a
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 132 deletions.
14 changes: 7 additions & 7 deletions 1.3base/Fx/Fx.js
Expand Up @@ -7,11 +7,11 @@ provides: [Fx.Specs]
...
*/
describe('Fx', function(){

beforeEach(function(){
this.clock = sinon.useFakeTimers();
});

afterEach(function(){
this.clock.reset();
this.clock.restore();
Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Fx', function(){

it('should cancel a Fx', function(){

var onCancel = jasmine.createSpy();
var onCancel = jasmine.createSpy('Fx.cancel');

var fx = new Fx({
duration: 50,
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('Fx', function(){
this.clock.tick(200);

expect(fx.foo).toEqual(10);

});

it('should pause and resume', function(){
Expand Down Expand Up @@ -115,7 +115,7 @@ describe('Fx', function(){
this.clock.tick(200);

expect(fx.foo).toEqual(1);

});

it('should chain the Fx', function(){
Expand All @@ -139,7 +139,7 @@ describe('Fx', function(){

it('should cancel the Fx after a new Fx:start with the link = cancel option', function(){

var onCancel = jasmine.createSpy('cancel');
var onCancel = jasmine.createSpy('Fx.cancel');

var fx = new Fx({
duration: 50,
Expand All @@ -148,7 +148,7 @@ describe('Fx', function(){
});

fx.start().start();

this.clock.tick(100);

expect(onCancel).toHaveBeenCalled();
Expand Down
30 changes: 15 additions & 15 deletions 1.3base/Types/Function.js
Expand Up @@ -10,7 +10,7 @@ provides: [Function.Specs]
describe('Function.bind', function(){

it('should return the function bound to an object', function(){
var spy = jasmine.createSpy();
var spy = jasmine.createSpy('Function.bind');
var f = spy.bind('MooTools');
expect(spy).not.toHaveBeenCalled();
f();
Expand All @@ -21,7 +21,7 @@ describe('Function.bind', function(){

it('should return the function bound to an object with specified argument', function(){
var binding = {some: 'binding'};
var spy = jasmine.createSpy().andReturn('something');
var spy = jasmine.createSpy('Function.bind with arg').andReturn('something');
var f = spy.bind(binding, 'arg');

expect(spy).not.toHaveBeenCalled();
Expand All @@ -31,7 +31,7 @@ describe('Function.bind', function(){

it('should return the function bound to an object with multiple arguments', function(){
var binding = {some: 'binding'};
var spy = jasmine.createSpy().andReturn('something');
var spy = jasmine.createSpy('Function.bind with multiple args').andReturn('something');
var f = spy.bind(binding, ['foo', 'bar']);

expect(spy).not.toHaveBeenCalled();
Expand All @@ -44,7 +44,7 @@ describe('Function.bind', function(){
describe('Function.pass', function(){

it('should return a function that when called passes the specified arguments to the original function', function(){
var spy = jasmine.createSpy().andReturn('the result');
var spy = jasmine.createSpy('Function.pass').andReturn('the result');
var fnc = spy.pass('an argument');
expect(spy).not.toHaveBeenCalled();
expect(fnc('additional', 'arguments')).toBe('the result');
Expand All @@ -53,7 +53,7 @@ describe('Function.pass', function(){
});

it('should pass multiple arguments and bind the function to a specific object when it is called', function(){
var spy = jasmine.createSpy().andReturn('the result');
var spy = jasmine.createSpy('Function.pass with bind').andReturn('the result');
var binding = {some: 'binding'};
var fnc = spy.pass(['multiple', 'arguments'], binding);
expect(spy).not.toHaveBeenCalled();
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('Function.attempt', function(){
});

it("should return the function's return value", function(){
var spy = jasmine.createSpy().andReturn('hello world!');
var spy = jasmine.createSpy('Function.attempt').andReturn('hello world!');
expect(spy.attempt()).toEqual('hello world!');
});

Expand All @@ -98,11 +98,11 @@ describe('Function.attempt', function(){
});

describe('Function.delay', function(){

beforeEach(function(){
this.clock = sinon.useFakeTimers();
});

afterEach(function(){
this.clock.reset();
this.clock.restore();
Expand All @@ -127,9 +127,9 @@ describe('Function.delay', function(){
});

it('should pass parameter 0', function(){
var spy = jasmine.createSpy();
var spy = jasmine.createSpy('Function.delay with 0');
spy.delay(50, null, 0);

this.clock.tick(100);
expect(spy).toHaveBeenCalledWith(0);
});
Expand All @@ -147,11 +147,11 @@ describe('Function.delay', function(){
});

describe('Function.periodical', function(){

beforeEach(function(){
this.clock = sinon.useFakeTimers();
});

afterEach(function(){
this.clock.reset();
this.clock.restore();
Expand All @@ -172,14 +172,14 @@ describe('Function.periodical', function(){
expect(spy).not.toHaveBeenCalled();

this.clock.tick(100);

expect(spy).not.toHaveBeenCalled();
});

it('should pass parameter 0', function(){
var spy = jasmine.createSpy();
var spy = jasmine.createSpy('Function.periodical with 0');
var timer = spy.periodical(10, null, 0);

this.clock.tick(100);

expect(spy).toHaveBeenCalledWith(0);
Expand Down
22 changes: 10 additions & 12 deletions 1.3client/Element/Element.Event.js
Expand Up @@ -7,20 +7,17 @@ provides: [Element.Event.Specs]
...
*/
describe('Element.Event', function(){

// Restore native fireEvent in IE for Syn
var createElement = function(tag, props){
var el = document.createElement(tag),
fireEvent = el.fireEvent;

$(el);
el.fireEvent = fireEvent;
var el = $(document.createElement(tag));
el.fireEvent = el._fireEvent;
return el.set(props);
};

it('Should trigger the click event', function(){
var callback = jasmine.createSpy();

var callback = jasmine.createSpy('Element.Event click');

var el = createElement('a', {
text: 'test',
Expand All @@ -34,23 +31,24 @@ describe('Element.Event', function(){
}
}).inject(document.body);

simulateEvent('click', [{}, el], function(){
Syn.click({}, el, function(){
alert('click!');
expect(callback).toHaveBeenCalled();
el.destroy();
});

});

// Only run this spec in browsers other than IE6-8 because they can't properly simulate key events
it('Should watch for a key-down event', function(){

var callback = jasmine.createSpy('keydown');

var div = createElement('div').addEvent('keydown', function(event){
callback(event.key);
}).inject(document.body);

simulateEvent('key', ['escape', div], function(){
Syn.key('escape', div, function(){
alert('escape');
expect(callback).toHaveBeenCalledWith('esc');
div.destroy();
});
Expand Down
6 changes: 3 additions & 3 deletions 1.3client/Element/IFrame.js
Expand Up @@ -8,9 +8,9 @@ provides: [IFrame.Specs]
*/
describe('IFrame', function(){

it('should call onload', function(){
it('(async) should call onload', function(){
runs(function(){
this.onComplete = jasmine.createSpy();
this.onComplete = jasmine.createSpy('IFrame onComplete');

this.iframe = new IFrame({
src: 'http://' + document.location.host,
Expand All @@ -29,4 +29,4 @@ describe('IFrame', function(){

});

});
});

0 comments on commit e8f724a

Please sign in to comment.