aboutsummaryrefslogtreecommitdiffstats
path: root/test/jqLiteSpec.js
diff options
context:
space:
mode:
authorMichał Gołębiowski2013-06-19 20:52:50 +0100
committerPete Bacon Darwin2013-06-19 20:53:24 +0100
commitf1b94b4b599ab701bc75b55bbbbb73c5ef329a93 (patch)
tree033c39426a25c8ac86dc7dc4efb1b4d05fe05272 /test/jqLiteSpec.js
parent0bfa29377d7a77b360ecd3209d56eeb4f68a5043 (diff)
downloadangular.js-f1b94b4b599ab701bc75b55bbbbb73c5ef329a93.tar.bz2
feat(jqLite): switch bind/unbind to more recent jQuery on/off
jQuery switched to a completely new event binding implementation as of 1.7.0, centering around on/off methods instead of previous bind/unbind. This patch makes jqLite match this implementation while still supporting previous bind/unbind methods.
Diffstat (limited to 'test/jqLiteSpec.js')
-rw-r--r--test/jqLiteSpec.js88
1 files changed, 56 insertions, 32 deletions
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index f121e1a0..f6630536 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -268,7 +268,7 @@ describe('jqLite', function() {
it('should emit $destroy event if element removed via remove()', function() {
var log = '';
var element = jqLite(a);
- element.bind('$destroy', function() {log+= 'destroy;';});
+ element.on('$destroy', function() {log+= 'destroy;';});
element.remove();
expect(log).toEqual('destroy;');
});
@@ -276,7 +276,7 @@ describe('jqLite', function() {
it('should emit $destroy event if an element is removed via html()', inject(function(log) {
var element = jqLite('<div><span>x</span></div>');
- element.find('span').bind('$destroy', log.fn('destroyed'));
+ element.find('span').on('$destroy', log.fn('destroyed'));
element.html('');
@@ -343,7 +343,7 @@ describe('jqLite', function() {
span = div.find('span'),
log = '';
- span.bind('click', function() { log+= 'click;'});
+ span.on('click', function() { log+= 'click;'});
browserTrigger(span);
expect(log).toEqual('click;');
@@ -705,7 +705,7 @@ describe('jqLite', function() {
});
- describe('bind', function() {
+ describe('on', function() {
it('should bind to window on hashchange', function() {
if (jqLite.fn) return; // don't run in jQuery
var eventFn;
@@ -727,7 +727,7 @@ describe('jqLite', function() {
detachEvent: noop
};
var log;
- var jWindow = jqLite(window).bind('hashchange', function() {
+ var jWindow = jqLite(window).on('hashchange', function() {
log = 'works!';
});
eventFn({type: 'hashchange'});
@@ -739,7 +739,7 @@ describe('jqLite', function() {
it('should bind to all elements and return functions', function() {
var selected = jqLite([a, b]);
var log = '';
- expect(selected.bind('click', function() {
+ expect(selected.on('click', function() {
log += 'click on: ' + jqLite(this).text() + ';';
})).toEqual(selected);
browserTrigger(a, 'click');
@@ -752,8 +752,8 @@ describe('jqLite', function() {
var elm = jqLite(a),
callback = jasmine.createSpy('callback');
- elm.bind('click keypress', callback);
- elm.bind('click', callback);
+ elm.on('click keypress', callback);
+ elm.on('click', callback);
browserTrigger(a, 'click');
expect(callback).toHaveBeenCalled();
@@ -767,7 +767,7 @@ describe('jqLite', function() {
it('should set event.target on IE', function() {
var elm = jqLite(a);
- elm.bind('click', function(event) {
+ elm.on('click', function(event) {
expect(event.target).toBe(a);
});
@@ -775,7 +775,7 @@ describe('jqLite', function() {
});
it('should have event.isDefaultPrevented method', function() {
- jqLite(a).bind('click', function(e) {
+ jqLite(a).on('click', function(e) {
expect(function() {
expect(e.isDefaultPrevented()).toBe(false);
e.preventDefault();
@@ -796,11 +796,11 @@ describe('jqLite', function() {
sibling = root.find('ul');
child = parent.find('span');
- parent.bind('mouseenter', function() { log += 'parentEnter;'; });
- parent.bind('mouseleave', function() { log += 'parentLeave;'; });
+ parent.on('mouseenter', function() { log += 'parentEnter;'; });
+ parent.on('mouseleave', function() { log += 'parentLeave;'; });
- child.bind('mouseenter', function() { log += 'childEnter;'; });
- child.bind('mouseleave', function() { log += 'childLeave;'; });
+ child.on('mouseenter', function() { log += 'childEnter;'; });
+ child.on('mouseleave', function() { log += 'childLeave;'; });
});
afterEach(function() {
@@ -854,6 +854,30 @@ describe('jqLite', function() {
});
});
+
+ // Only run this test for jqLite and not normal jQuery
+ if ( _jqLiteMode ) {
+ it('should throw an error if eventData or a selector is passed', function() {
+ var elm = jqLite(a),
+ anObj = {},
+ aString = '',
+ aValue = 45,
+ callback = function() {};
+
+ expect(function() {
+ elm.on('click', anObj, callback);
+ }).toThrow();
+
+ expect(function() {
+ elm.on('click', null, aString, callback);
+ }).toThrow();
+
+ expect(function() {
+ elm.on('click', aValue, callback);
+ }).toThrow();
+
+ });
+ }
});
@@ -861,9 +885,9 @@ describe('jqLite', function() {
it('should do nothing when no listener was registered with bound', function() {
var aElem = jqLite(a);
- aElem.unbind();
- aElem.unbind('click');
- aElem.unbind('click', function() {});
+ aElem.off();
+ aElem.off('click');
+ aElem.off('click', function() {});
});
@@ -872,8 +896,8 @@ describe('jqLite', function() {
clickSpy = jasmine.createSpy('click'),
mouseoverSpy = jasmine.createSpy('mouseover');
- aElem.bind('click', clickSpy);
- aElem.bind('mouseover', mouseoverSpy);
+ aElem.on('click', clickSpy);
+ aElem.on('mouseover', mouseoverSpy);
browserTrigger(a, 'click');
expect(clickSpy).toHaveBeenCalledOnce();
@@ -883,7 +907,7 @@ describe('jqLite', function() {
clickSpy.reset();
mouseoverSpy.reset();
- aElem.unbind();
+ aElem.off();
browserTrigger(a, 'click');
expect(clickSpy).not.toHaveBeenCalled();
@@ -897,8 +921,8 @@ describe('jqLite', function() {
clickSpy = jasmine.createSpy('click'),
mouseoverSpy = jasmine.createSpy('mouseover');
- aElem.bind('click', clickSpy);
- aElem.bind('mouseover', mouseoverSpy);
+ aElem.on('click', clickSpy);
+ aElem.on('mouseover', mouseoverSpy);
browserTrigger(a, 'click');
expect(clickSpy).toHaveBeenCalledOnce();
@@ -908,7 +932,7 @@ describe('jqLite', function() {
clickSpy.reset();
mouseoverSpy.reset();
- aElem.unbind('click');
+ aElem.off('click');
browserTrigger(a, 'click');
expect(clickSpy).not.toHaveBeenCalled();
@@ -917,7 +941,7 @@ describe('jqLite', function() {
mouseoverSpy.reset();
- aElem.unbind('mouseover');
+ aElem.off('mouseover');
browserTrigger(a, 'mouseover');
expect(mouseoverSpy).not.toHaveBeenCalled();
});
@@ -928,8 +952,8 @@ describe('jqLite', function() {
clickSpy1 = jasmine.createSpy('click1'),
clickSpy2 = jasmine.createSpy('click2');
- aElem.bind('click', clickSpy1);
- aElem.bind('click', clickSpy2);
+ aElem.on('click', clickSpy1);
+ aElem.on('click', clickSpy2);
browserTrigger(a, 'click');
expect(clickSpy1).toHaveBeenCalledOnce();
@@ -938,7 +962,7 @@ describe('jqLite', function() {
clickSpy1.reset();
clickSpy2.reset();
- aElem.unbind('click', clickSpy1);
+ aElem.off('click', clickSpy1);
browserTrigger(a, 'click');
expect(clickSpy1).not.toHaveBeenCalled();
@@ -946,7 +970,7 @@ describe('jqLite', function() {
clickSpy2.reset();
- aElem.unbind('click', clickSpy2);
+ aElem.off('click', clickSpy2);
browserTrigger(a, 'click');
expect(clickSpy2).not.toHaveBeenCalled();
});
@@ -1159,9 +1183,9 @@ describe('jqLite', function() {
clickSpy1 = jasmine.createSpy('clickSpy1'),
clickSpy2 = jasmine.createSpy('clickSpy2');
- element.bind('poke', pokeSpy);
- element.bind('click', clickSpy1);
- element.bind('click', clickSpy2);
+ element.on('poke', pokeSpy);
+ element.on('click', clickSpy1);
+ element.on('click', clickSpy2);
expect(pokeSpy).not.toHaveBeenCalled();
expect(clickSpy1).not.toHaveBeenCalled();
@@ -1185,7 +1209,7 @@ describe('jqLite', function() {
pokeSpy = jasmine.createSpy('poke'),
event;
- element.bind('click', pokeSpy);
+ element.on('click', pokeSpy);
element.triggerHandler('click');
event = pokeSpy.mostRecentCall.args[0];