title: How to unit test jQuery keyboard events?
body: <p>Is there a way to test JavaScript keyboard event handlers (for <code>keypress</code>, <code>keyup</code>, <code>keydown</code> events)?</p>
  
  <p>I know I can declare event handlers like this:</p>
  
  <pre><code>function keyUpEvHandler(e) {
      ... // code here
  }
  
  $('#myId').keyup(keyUpEvHandler);
  </code></pre>
  
  <p>and then just run this function in unit tests, but I will have to prepare event argument object to be the same as passed when actual key is pressed:</p>
  
  <pre><code>var e = {keyCode: 70, ...};
  </code></pre>
  
  <p>Is there any way to trigger this event and pass key code as an argument or something similar? Unfortunately <a href="http://docs.jquery.com/Events/trigger" rel="noreferrer">jQuery trigger() docs</a> doesn't cover keyboard events.</p>