aboutsummaryrefslogtreecommitdiffstats
path: root/test/jqLiteSpec.js
diff options
context:
space:
mode:
authorMatias Niemelä2013-11-28 01:10:28 -0500
committerMatias Niemelä2013-12-19 14:39:04 -0500
commit937caab6475e53a7ea0206e992f8a52449232e78 (patch)
tree35227c9aa11914b11c9cab1c00d75e8a8f783fe6 /test/jqLiteSpec.js
parent3fc8017119497207c8e300e4014b4b2f62585bec (diff)
downloadangular.js-937caab6475e53a7ea0206e992f8a52449232e78.tar.bz2
feat(jqLite): provide support for element.one()
Diffstat (limited to 'test/jqLiteSpec.js')
-rw-r--r--test/jqLiteSpec.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 3a8fd404..931f9b2e 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -1177,6 +1177,63 @@ describe('jqLite', function() {
}
});
+ describe('one', function() {
+
+ it('should only fire the callback once', function() {
+ var element = jqLite(a);
+ var spy = jasmine.createSpy('click');
+
+ element.one('click', spy);
+
+ browserTrigger(element, 'click');
+ expect(spy).toHaveBeenCalledOnce();
+
+ browserTrigger(element, 'click');
+ expect(spy).toHaveBeenCalledOnce();
+ });
+
+ it('should deregister when off is called', function() {
+ var element = jqLite(a);
+ var spy = jasmine.createSpy('click');
+
+ element.one('click', spy);
+ element.off('click', spy);
+
+ browserTrigger(element, 'click');
+ expect(spy).not.toHaveBeenCalled();
+ });
+
+ it('should return the same event object just as on() does', function() {
+ var element = jqLite(a);
+ var eventA, eventB;
+ element.on('click', function(event) {
+ eventA = event;
+ });
+ element.one('click', function(event) {
+ eventB = event;
+ });
+
+ browserTrigger(element, 'click');
+ expect(eventA).toEqual(eventB);
+ });
+
+ it('should not remove other event handlers of the same type after execution', function() {
+ var element = jqLite(a);
+ var calls = [];
+ element.one('click', function(event) {
+ calls.push('one');
+ });
+ element.on('click', function(event) {
+ calls.push('on');
+ });
+
+ browserTrigger(element, 'click');
+ browserTrigger(element, 'click');
+
+ expect(calls).toEqual(['one','on','on']);
+ });
+ });
+
describe('replaceWith', function() {
it('should replaceWith', function() {