title: Simulating Enter Key Press on Input in Karma/Jasmine Tests
body: <p>I am trying to test user search functionality inside an angular custom component. The input (and only input) in the directive template that I am trying add text to and trigger the search is:</p>
  
  <pre><code> &lt;input type="text" ng-model="searchInput" class="form-control search"/&gt;
  </code></pre>
  
  <p>I would like to add a text value of "User" into that input above. Test to make sure it has that value, and then simulate an enter key press to then select the first matching node.</p>
  
  <ol>
  <li>Get the input element</li>
  <li>Add text to the input</li>
  <li>Test to make sure the input value is correct</li>
  <li>Press enter on the input</li>
  <li>Text to make sure the first matching item in the search is correct</li>
  </ol>
  
  <p>Have tried:</p>
  
  <pre><code>   it ("should search for the specified node", function () {
                var value = "User is not registered"
  
                 var input = diagramDirective.find("input");
  
                 $(input).val(value).trigger("input");
                 scope.$apply();
  
                 //why can't I trigger a click event here by doing something like
                 var e = jQuery.Event("keypress");
                 e.keyCode = 13;
  
                 $(input).trigger(e);
  
  
      }
  </code></pre>
  
  <p>Thanks</p>