Skip to content

Instantly share code, notes, and snippets.

@Elexy
Last active December 19, 2015 19:49
Show Gist options
  • Save Elexy/6009322 to your computer and use it in GitHub Desktop.
Save Elexy/6009322 to your computer and use it in GitHub Desktop.
Testing hammer.js inside Angular app with Karma e2e testing. Include this file in your e2e config together with https://github.com/jtangelder/faketouches.js and you can simulate taps and doubletaps using this DSL extension. The other gestures are easily added... if you don't like the coffeescript just run it through http://js2coffee.org/ to get …
###
Usage:
hammer(selector).tap() trigger a Hammer Tap event
hammer(selector).doubleTap() trigger a Hammer DoubleTap event
###
angular.scenario.dsl "hammer", () ->
hammerTime = {}
hammerTime.tap = () ->
@addFutureAction "element '" + @label + "' tap", ($window, $document, done) ->
elements = $document.elements()
href = elements.attr("href")
eventProcessDefault = elements.trigger("click")[0]
faker = new FakeTouches elements[0]
faker.triggerGesture 'Tap', () ->
if href and elements[0].nodeName.toUpperCase() is "A" and eventProcessDefault
@application.navigateTo href, (->
done()
), done
else
done()
hammerTime.doubleTap = () ->
@addFutureAction "element '" + @label + "' doubleTap", ($window, $document, done) ->
elements = $document.elements()
href = elements.attr("href")
eventProcessDefault = elements.trigger("click")[0]
faker = new FakeTouches elements[0]
faker.triggerGesture 'DoubleTap', () ->
if href and elements[0].nodeName.toUpperCase() is "A" and eventProcessDefault
@application.navigateTo href, (->
done()
), done
else
done()
(selector) ->
this.dsl.using selector
hammerTime
basePath = '../';
files = [
ANGULAR_SCENARIO,
ANGULAR_SCENARIO_ADAPTER,
'spec/javascripts/angular/lib/faketouches.js',
'spec/javascripts/angular/lib/angular-faketouches.coffee',
'spec/javascripts/angular/e2e/**/*.js',
'spec/javascripts/angular/e2e/**/*.coffee'
];
autoWatch = true;
browsers = ['Chrome'];
singleRun = false;
proxies = {
'/': 'http://localhost:3003/'
};
urlRoot = '/_karma_/';
junitReporter = {
outputFile: 'test_out/e2e.xml',
suite: 'e2e'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment