title: Simulating user input for TDD JavaScript
body: <p>I'm finding it increasingly difficult to simulate actual user events using jQuery or native element trigger functions. For example, if you have a text input and you don't want the user to be able to add a character, you can call <code>e.preventDefault()</code> with the jQuery-normalised event object on the <code>keydown</code> event. However, there is no way to programatically verify this test scenario.</p>
  
  <p>The following test passes even without the call to <code>preventDefault</code> because the jQuery keydown trigger isn't a "real" event.</p>
  
  <pre><code>input.val('test').trigger(jQuery.Event({
      which: 68
  });
  expect(input).toHaveValue('test');
  </code></pre>
  
  <p>Without the correct code, this test should fail because the input should have a value of 'testd' (68 is the character code for 'd').</p>
  
  <p>Does anyone know any methods or libraries to simulate <strong>real</strong> browser UI events?</p>