Fixed #153 with tests

This commit is contained in:
Max Lynch
2013-11-17 15:14:02 -06:00
parent 531044e9b0
commit ea2ff85e91
5 changed files with 58 additions and 4 deletions

View File

@ -4,6 +4,9 @@ angular.module('ionic.service.gesture', [])
return {
on: function(eventType, cb, $element) {
return window.ionic.onGesture(eventType, cb, $element[0]);
},
off: function(gesture, eventType, cb) {
return window.ionic.offGesture(gesture, eventType, cb);
}
};
}]);

View File

@ -0,0 +1,48 @@
describe('Ionic Gesture Service', function() {
var gesture;
beforeEach(module('ionic.service.gesture'));
beforeEach(inject(function(Gesture) {
gesture = Gesture;
}));
iit('Should bind', function() {
var el = document.createElement('div');
var handlers = {
dragHandle: function(e) {
}
};
spyOn(handlers, 'dragHandle');
gesture.on('drag', handlers.dragHandle, angular.element(el));
var event = new CustomEvent('drag', { target: el });
el.dispatchEvent(event);
expect(handlers.dragHandle).toHaveBeenCalled();
});
iit('Should unbind', function() {
var el = document.createElement('div');
var handlers = {
dragHandle: function(e) {
}
};
spyOn(handlers, 'dragHandle');
var g = gesture.on('drag', handlers.dragHandle, angular.element(el));
var event = new CustomEvent('drag', { target: el });
el.dispatchEvent(event);
expect(handlers.dragHandle).toHaveBeenCalled();
gesture.off(g, 'drag', handlers.dragHandle);
var event = new CustomEvent('drag', { target: el });
el.dispatchEvent(event);
expect(handlers.dragHandle).toHaveBeenCalled();
});
})