Skip to content

Commit

Permalink
Simplify keyPress emulation
Browse files Browse the repository at this point in the history
Former-commit-id: 93e8d8a
  • Loading branch information
princed committed Aug 22, 2014
1 parent ea31285 commit 22a3e46
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
4 changes: 3 additions & 1 deletion karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module.exports = function (karma) {
var prepareWbpackConf = function (webpackConf) {
webpackConf.devtool = 'eval';
webpackConf.output = {};
webpackConf.resolve.root = __dirname + '/test-helpers/';

return webpackConf;
};

Expand All @@ -21,7 +23,7 @@ module.exports = function (karma) {
// Files are given outside from gulp task
files: [
'node_modules/jquery/dist/jquery.js',
'test-helpers/*.js',
'test-helpers/phantomjs-shims.js',
'src/components/**/*.test.js'
],

Expand Down
14 changes: 5 additions & 9 deletions src/components/shortcuts/shortcuts.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var keyEvent = require('imports?window=>{}!exports?window.KeyEvent!Mousetrap/tests/libs/key-event');
var simulateKeypress = require('simulate-keypress');
var Shortcuts = require('./shortcuts');
var shortcuts = Shortcuts.getInstance();

Expand All @@ -9,6 +9,10 @@ describe('Shortcuts', function () {
var key2 = 'b';
var scope = 'scope scope scope';

function trigger() {
simulateKeypress(key, 65);
}

beforeEach(function() {
shortcuts.reset();
shortcuts.setScope();
Expand Down Expand Up @@ -105,10 +109,6 @@ describe('Shortcuts', function () {
});

describe('Filter', function () {
function trigger() {
keyEvent.simulate(key.charCodeAt(0), 65);
}

it('Should setFilter', function () {
shortcuts.setFilter(noop2);
shortcuts.bind({key: key, handler: noop});
Expand All @@ -135,10 +135,6 @@ describe('Shortcuts', function () {
});

describe('Key press', function () {
function trigger() {
Shortcuts.trigger(key);
}

it('Should handle keys in root scope', function () {
shortcuts.bind({key: key, handler: noop});

Expand Down
7 changes: 7 additions & 0 deletions test-helpers/simulate-keypress.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var keyEvent = require('imports?window=>{}!exports?window.KeyEvent!Mousetrap/tests/libs/key-event');

module.exports = function(char, keyCode) {
var charCode = char && char.charCodeAt(0) || 0;

return keyEvent.simulate(charCode, keyCode || 0);
};

0 comments on commit 22a3e46

Please sign in to comment.