title: Angular 4 unit test for KeyboardEvent
body: <p>I'm trying to write a unit test for a utility I've written to limit the characters available to an input field.  The method takes the keyboard event and determines which event.code has been fired and either returns true or event.preventDefault().  This works great but I cannot test it in jasmine / karma.</p>
  
  <p>Current input from template</p>
  
  <pre><code>&lt;input [(ngModel)]="donationValue" formControlName="donationAmount" 
  type="tel" class="donation-amount" (keydown)="checkCharacter($event)" 
  placeholder="Enter Amount..."/&gt;
  </code></pre>
  
  <p>Here is my current test</p>
  
  <pre><code>it('should return have defaultPrevented as true', fakeAsync(() =&gt; {
          const goalInput = 
  fixture.debugElement.query(By.css('input.donation-
  amount')).nativeElement;
          const keyEventData = { isTrusted: true, code: 'KeyA' };
          const keyEvent = new KeyboardEvent('keydown', keyEventData);
          goalInput.dispatchEvent(keyEvent);
          tick();
          fixture.detectChanges();                
          expect(keyEvent.defaultPrevented).toBe(true);
      }));
  </code></pre>
  
  <p>I have other tests that I have spied on the methods and they are getting fired off.  My suspicion is that the isTrusted property is set to false even though I'm trying to set it to true.</p>