K
K
KoRNeT46RuS2016-12-16 10:35:56
JavaScript
KoRNeT46RuS, 2016-12-16 10:35:56

How to trigger ctrl+enter key combination in js?

It is necessary to call the combination of keys control + inter for the test in karma.
Tried through

angular.element(document.querySelector('main > div')).trigger({type: 'keydown', which: 13}, {type: 'keydown', which: 17});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stepanya, 2016-12-16
@Stepanya

Why are you testing UI in Karma? Test controllers, their public functions and possibly private ones

Y
Yuriy Berg, 2016-12-16
@art_haacki

var myApp = angular.module('myApp', []);

myApp.controller('Ctrl', function($scope) {


    $scope.keyBuffer = [];

    function arrays_equal(a,b) { return !(a<b || b<a); }

    $scope.down = function(e) {

      $scope.keyBuffer.push(e.keyCode);

      var upUp = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
      if (arrays_equal(upUp, $scope.keyBuffer)) {

        alert('thats it!');
      }
    };

  });

https://goo.gl/SyjqkT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question