title: How to create KeyboardEvent with specific keyCode
body: <p>I'm trying to simulate a keydown event in a unit test (angular2/TypeScript). I do not always have a DebugElement available, so I'm trying to emit the event on a native element.
  The problem I have is how to define the keyCode when creating the KeyboardEvent.
  The keyCode is not defined as part of KeyboardEventInit definition, and on the KeyboardEvent itself it is only exposed as a readonly property. </p>
  
  <p>Simply just adding a keyCode property (and set the obj type as ) doesn't work either.</p>
  
  <pre><code>    let elm = &lt;HTMLElement&gt;content.nativeElement;
      let ev = new KeyboardEvent('keydown', {
          code: '123',
          //keyCode: 345,
          key: 'a',
      });
      elm.dispatchEvent(ev);
  </code></pre>
  
  <p>Any suggestions ?</p>
  
  <p>Edit: 
  According to the mdn link, keyCode is deprecated and should not be used, instead 'code' should be used.
  <a href="https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode</a></p>