jQuery Trigger Event in AngularJS Karma Test

前端 未结 2 1833
别那么骄傲
别那么骄傲 2021-01-05 11:10

I\'m trying to test a new directive I\'m writing. However, I can\'t seem to get the keydown event to trigger with jQuery inside Karma/Jasmine.

Here is a simplified

2条回答
  •  礼貌的吻别
    2021-01-05 11:36

    I hope this works

      var e = $.Event('keydown');
      e.which = 65;
    
      $(inputEl).trigger(e); // convert inputEl into a jQuery object first
      // OR
      angular.element(inputEl).triggerHandler(e); // angular.element uses triggerHandler instead of trigger to trigger events
    

提交回复
热议问题