Permalink
Browse files

All green. Removed simulateEvent usage. Added names to each spy.

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...
1 parent 2fb8412 commit e8f724a51dc9d7ff3791023cac2501932a0bc446 @ibolmo ibolmo committed Nov 25, 2011
View
14 1.3base/Fx/Fx.js
@@ -7,11 +7,11 @@ provides: [Fx.Specs]
...
*/
describe('Fx', function(){
-
+
beforeEach(function(){
this.clock = sinon.useFakeTimers();
});
-
+
afterEach(function(){
this.clock.reset();
this.clock.restore();
@@ -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,
@@ -82,7 +82,7 @@ describe('Fx', function(){
this.clock.tick(200);
expect(fx.foo).toEqual(10);
-
+
});
it('should pause and resume', function(){
@@ -115,7 +115,7 @@ describe('Fx', function(){
this.clock.tick(200);
expect(fx.foo).toEqual(1);
-
+
});
it('should chain the Fx', function(){
@@ -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,
@@ -148,7 +148,7 @@ describe('Fx', function(){
});
fx.start().start();
-
+
this.clock.tick(100);
expect(onCancel).toHaveBeenCalled();
View
30 1.3base/Types/Function.js
@@ -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();
@@ -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();
@@ -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();
@@ -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');
@@ -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();
@@ -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!');
});
@@ -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();
@@ -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);
});
@@ -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();
@@ -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);
View
22 1.3client/Element/Element.Event.js
@@ -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',
@@ -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();
});
View
6 1.3client/Element/IFrame.js
@@ -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,
@@ -29,4 +29,4 @@ describe('IFrame', function(){
});
-});
+});
View
75 1.3client/Request/Request.HTML.js
@@ -16,24 +16,25 @@ describe('Request.HTML', function(){
requests.push(xhr);
};
});
-
+
afterEach(function(){
- this.xhr.restore();
+ this.xhr.restore();
});
it('should create an ajax request and pass the right arguments to the onComplete event', function(){
var response = '<body><img><div><span>res&amp;ponsé</span></div><script>___SPEC___=5;</script></body>';
-
+
+ this.spy.identity = 'Request.HTML onComplete';
var request = new Request.HTML({
url: '../Helpers/request.php',
onComplete: this.spy
}).send();
this.requests[0].respond(200, {'Content-Type': 'text/html'}, response);
-
+
expect(this.spy.wasCalled).toBe(true);
-
+
// checks arguments order
expect(this.spy).toHaveBeenCalledWith(request.response.tree, request.response.elements, request.response.html, request.response.javascript);
var onCompleteArgs = this.spy.argsForCall[0];
@@ -45,8 +46,8 @@ describe('Request.HTML', function(){
expect(___SPEC___).toEqual(5);
});
-
- xit('should create an ajax request and correctly generate the tree response from a tr', function(){
+
+ xit('(async) should create an ajax request and correctly generate the tree response from a tr', function(){
runs(function(){
this.request = new Request.HTML({
@@ -63,15 +64,15 @@ describe('Request.HTML', function(){
runs(function(){
var onCompleteArgs = this.spy.argsForCall[0];
-
+
expect(onCompleteArgs[0][0].nodeName).toEqual('TR');
expect(onCompleteArgs[1][1].nodeName).toEqual('TD');
expect(onCompleteArgs[2]).toEqual('<tr><td>text</td></tr>');
});
});
-
- xit('should create an ajax request and correctly generate the tree response from options', function(){
+
+ xit('(async) should create an ajax request and correctly generate the tree response from options', function(){
runs(function(){
this.request = new Request.HTML({
@@ -88,23 +89,24 @@ describe('Request.HTML', function(){
runs(function(){
var onCompleteArgs = this.spy.argsForCall[0];
-
+
expect(onCompleteArgs[0].length).toEqual(3);
expect(onCompleteArgs[1].length).toEqual(3);
expect(onCompleteArgs[2]).toEqual('<option>1</option><option>2</option><option>3</option>');
expect(onCompleteArgs[3]).toBeFalsy();
-
+
var firstOption = onCompleteArgs[0][0];
expect(firstOption.tagName).toEqual('OPTION');
expect(firstOption.innerHTML).toEqual('1');
});
});
-
+
it('should create an ajax request and correctly update an element with the response', function(){
-
+
var response = '<span>text</span>';
-
+
+ this.spy.identity = 'Request.HTML onComplete update element';
new Element('div', {'id': 'update', 'html': '<div>some</div>'}).inject(document.body);
this.request = new Request.HTML({
url: '../Helpers/request.php',
@@ -113,7 +115,7 @@ describe('Request.HTML', function(){
}).send();
this.requests[0].respond(200, {'Content-Type': 'text/html'}, response);
-
+
expect(this.spy.wasCalled).toBe(true);
var update = $('update');
@@ -124,18 +126,19 @@ describe('Request.HTML', function(){
});
it('should create an ajax request and correctly append the response to an element', function(){
-
+
var response = '<div><span>text</span><p>paragraph</p></div>';
-
+
new Element('div', {'id': 'update', 'html': '<div>some</div>'}).inject(document.body);
+ this.spy.identity = 'Request.HTML onComplete ajax append';
this.request = new Request.HTML({
url: '../Helpers/request.php',
onComplete: this.spy,
append: 'update'
}).send();
-
+
this.requests[0].respond(200, {'Content-Type': 'text/html'}, response);
-
+
expect(this.spy.wasCalled).toBe(true);
var update = $('update');
@@ -149,33 +152,35 @@ describe('Request.HTML', function(){
expect(div.getLast().get('tag')).toEqual('p');
expect(div.getLast().get('text')).toEqual('paragraph');
update.dispose();
-
+
});
-
+
it('should create an ajax request and correctly filter it by the passed selector', function(){
-
+
var response = '<span>text</span><a>aaa</a>';
-
+
+ this.spy.identity = 'Request.HTML onComplete filter';
var request = new Request.HTML({
url: '../Helpers/request.php',
onComplete: this.spy,
filter: 'a'
}).send();
-
+
this.requests[0].respond(200, {'Content-Type': 'text/html'}, response);
expect(this.spy.wasCalled).toBe(true);
var onCompleteArgs = this.spy.argsForCall[0];
expect(onCompleteArgs[0].length).toEqual(1);
expect(onCompleteArgs[0][0].get('tag')).toEqual('a');
expect(onCompleteArgs[0][0].get('text')).toEqual('aaa');
-
+
});
it('should create an ajax request that filters the response and updates the target', function(){
-
+
var response = '<div>text<p><a>a link</a></p></div>';
-
+
+ this.spy.identity = 'Request.HTML onComplete update and filter';
new Element('div', {'id': 'update', 'html': '<div>some</div>'}).inject(document.body);
this.request = new Request.HTML({
url: '../Helpers/request.php',
@@ -192,14 +197,15 @@ describe('Request.HTML', function(){
expect(update.getFirst().get('tag')).toEqual('a');
expect(update.getFirst().get('text')).toEqual('a link');
update.dispose();
-
+
});
it('should create an ajax request that filters the response and appends to the target', function(){
-
+
var response = '<div>text<p><a>a link</a></p></div>';
-
+
new Element('div', {'id': 'update', 'html': '<div>some</div>'}).inject(document.body);
+ this.spy.identity = 'Request.HTML onComplete append and filter';
this.request = new Request.HTML({
url: '../Helpers/request.php',
onComplete: this.spy,
@@ -214,15 +220,16 @@ describe('Request.HTML', function(){
expect(update.getChildren().length).toEqual(2);
expect(update.get('html').toLowerCase()).toEqual('<div>some</div><a>a link</a>');
update.dispose();
-
+
});
it('should create an ajax request through Element.load', function(){
var element = new Element('div');
var response = 'hello world!';
-
+
+ this.spy.identity = 'Request.HTML onComplete load';
var request = element.set('load', {
url: '../Helpers/request.php',
onComplete: this.spy
@@ -243,5 +250,5 @@ describe('Request.HTML', function(){
});
});
-
+
});
View
20 1.3client/Request/Request.JSON.js
@@ -16,44 +16,46 @@ describe('Request.JSON', function(){
requests.push(xhr);
};
});
-
+
afterEach(function(){
- this.xhr.restore();
+ this.xhr.restore();
});
it('should create a JSON request', function(){
var response = '{"ok":true}';
-
+
+ this.spy.identity = 'Requst.JSON';
this.request = new Request.JSON({
url: '../Helpers/request.php',
onComplete: this.spy
}).send({data: {
'__response': response
}});
-
+
this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
expect(this.spy.wasCalled).toBe(true);
-
+
// checks the first argument from the first call
expect(this.spy.argsForCall[0][0]).toEqual({ok: true});
-
+
});
it('should fire the error event', function(){
var response = '{"ok":function(){invalid;}}';
-
+
+ this.spy.identity = 'Requst.JSON error';
this.request = new Request.JSON({
url: '../Helpers/request.php',
onError: this.spy
}).send({data: {
'__response': response
}});
-
+
this.requests[0].respond(200, {'Content-Type': 'text/json'}, response);
expect(this.spy.wasCalled).toBe(true);
-
+
// checks the first argument from the first call
expect(this.spy.argsForCall[0][0]).toEqual('{"ok":function(){invalid;}}');
View
60 1.3client/Request/Request.js
@@ -7,75 +7,75 @@ provides: [Request.Specs]
...
*/
describe('Request', function(){
-
+
beforeEach(function(){
this.xhr = sinon.useFakeXMLHttpRequest();
var requests = this.requests = [];
this.xhr.onCreate = function(xhr){
requests.push(xhr);
};
});
-
+
afterEach(function(){
this.xhr.restore();
});
it('should create an ajax request', function(){
- var onComplete = jasmine.createSpy();
-
+ var onComplete = jasmine.createSpy('Request onComplete');
+
var request = new Request({
url: '/',
onComplete: onComplete
}).send({data: {
'__response': 'res&amp;ponsé'
}});
-
+
this.requests[0].respond(200, {'Content-Type': 'text/plain'}, 'res&amp;ponsé');
-
+
// checks the first argument from the first call
expect(onComplete.argsForCall[0][0]).toEqual('res&amp;ponsé');
-
+
});
-
+
it('should create a Request with method get and sending data', function(){
- var onComplete = jasmine.createSpy();
-
+ var onComplete = jasmine.createSpy('Request onComplete data');
+
var request = new Request({
url: '../Helpers/request.php',
method: 'get',
onComplete: onComplete
}).send({data: {'some': 'data'}});
-
+
var response = {method: 'get', 'get': {'some':'data'}};
this.requests[0].respond(200, {'Content-Type': 'text/json'}, JSON.encode(response));
-
+
expect(onComplete.wasCalled).toBe(true);
-
+
expect(JSON.decode(onComplete.argsForCall[0][0])).toEqual(response);
-
+
});
-
+
it('the options passed on the send method should rewrite the current ones', function(){
- var onComplete = jasmine.createSpy();
+ var onComplete = jasmine.createSpy('Request onComplete rewrite data');
var request = new Request({
url: '../Helpers/request.php',
method: 'get',
data: {'setup': 'data'},
onComplete: onComplete
}).send({method: 'post', data: {'send': 'senddata'}});
-
+
var requested = this.requests[0];
-
+
expect(requested.method.toLowerCase()).toBe('post');
-
+
requested.respond(200, {'Content-Type': 'text/plain'}, '');
-
+
expect(onComplete.wasCalled).toBe(true);
});
-
- xit('should create an ajax request and as it\'s an invalid XML, onComplete will receive null as the xml document', function(){
+
+ xit('(async) should create an ajax request and as it\'s an invalid XML, onComplete will receive null as the xml document', function(){
runs(function(){
this.onComplete = jasmine.createSpy();
@@ -87,38 +87,38 @@ describe('Request', function(){
'__response': 'response'
}});
});
-
+
waitsFor(800, function(){
return this.onComplete.wasCalled;
});
-
+
runs(function(){
expect(this.onComplete.argsForCall[0][0]).toEqual('response');
expect(this.request.response.text).toEqual('response');
});
-
+
runs(function(){
this.chain = jasmine.createSpy();
this.request.chain(this.chain).send({data: {
'__type': 'xml',
'__response': '<node>response</node><no></no>'
}});
});
-
+
waitsFor(800, function(){
return this.chain.wasCalled;
});
-
+
runs(function(){
expect(this.onComplete.argsForCall[0][0]).toEqual('<node>response</node><no></no>');
expect(this.request.response.text).toEqual('<node>response</node><no></no>');
});
-
+
});
it('should not overwrite the data object', function(){
- var onComplete = jasmine.createSpy();
+ var onComplete = jasmine.createSpy('Request onComplete overwrite protection');
var request = new Request({
url: '../Helpers/request.php',
data: {
@@ -129,7 +129,7 @@ describe('Request', function(){
var requested = this.requests[0];
requested.respond(200, {'Content-Type': 'text/plain'}, requested.requestBody)
-
+
expect(onComplete.wasCalled).toBe(true);
expect(onComplete.argsForCall[0][0]).toEqual('__response=data');
View
15 1.4client/Element/Element.Event.js
@@ -11,17 +11,14 @@ describe('Element.Event + DOMEvent', 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 and prevent the default behavior', function(){
- var callback = jasmine.createSpy();
+ var callback = jasmine.createSpy('Element.Event click with prevent');
var el = createElement('a', {
text: 'test',
@@ -38,7 +35,7 @@ describe('Element.Event + DOMEvent', function(){
}
}).inject(document.body);
- simulateEvent('click', [{}, el], function(){
+ Syn.click({}, el, function(){
expect(callback).toHaveBeenCalled();
el.destroy();
});
@@ -62,7 +59,7 @@ describe('Element.Event', function(){
it('should pass the name of the custom event to the callbacks', function(){
var callbacks = 0;
- var callback = jasmine.createSpy();
+ var callback = jasmine.createSpy('Element.Event custom');
var fn = function(anything, type){
expect(type).toEqual('customEvent');
@@ -84,7 +81,7 @@ describe('Element.Event', function(){
var div = createElement('div').addEvent('customEvent', callback).inject(document.body);
- simulateEvent('click', [{}, div], function(){
+ Syn.click({}, div, function(){
expect(callback).toHaveBeenCalled();
div.removeEvent('customEvent', callback).destroy();
expect(callbacks).toEqual(3);
View
26 2.0base/Types/Function.js
@@ -42,7 +42,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 return').andReturn('hello world!');
expect(spy.attempt()).toEqual('hello world!');
});
@@ -58,7 +58,7 @@ describe('Function.attempt', function(){
describe('Function.bind', function(){
it('should return the function bound to an object', function(){
- var spy = jasmine.createSpy();
+ var spy = jasmine.createSpy('Function.bind bound');
var f = spy.bind('MooTools');
expect(spy).not.toHaveBeenCalled();
f();
@@ -69,7 +69,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 binding').andReturn('something');
var f = spy.bind(binding, 'arg');
expect(spy).not.toHaveBeenCalled();
@@ -80,7 +80,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 binding with arguments').andReturn('something');
var f = spy.bind(binding, 'foo', 'bar');
expect(spy).not.toHaveBeenCalled();
@@ -94,7 +94,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 with argument').andReturn('the result');
var fnc = spy.pass('an argument');
expect(spy).not.toHaveBeenCalled();
expect(fnc('additional', 'arguments')).toBe('the result');
@@ -103,7 +103,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 many arguments').andReturn('the result');
var binding = {some: 'binding'};
var fnc = spy.pass(['multiple', 'arguments'], binding);
expect(spy).not.toHaveBeenCalled();
@@ -125,11 +125,11 @@ describe('Function.extend', function(){
});
describe('Function.delay', function(){
-
+
beforeEach(function(){
this.clock = sinon.useFakeTimers();
});
-
+
afterEach(function(){
this.clock.reset();
this.clock.restore();
@@ -155,7 +155,7 @@ describe('Function.delay', function(){
});
it('should pass parameter 0', function(){
- var spy = jasmine.createSpy();
+ var spy = jasmine.createSpy('Function.pass with 0');
spy.delay(50, null, 0);
this.clock.tick(100);
@@ -177,16 +177,16 @@ describe('Function.delay', function(){
});
describe('Function.periodical', function(){
-
+
beforeEach(function(){
this.clock = sinon.useFakeTimers();
});
-
+
afterEach(function(){
this.clock.reset();
this.clock.restore();
});
-
+
it('should return an interval pointer', function(){
var spy = jasmine.createSpy('Bond');
@@ -207,7 +207,7 @@ describe('Function.periodical', function(){
});
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);

0 comments on commit e8f724a

Please sign in to comment.