title: Unable to simulate keypress event in Angular 2 unit test (Jasmine)
body: <p>I am using a directive to get the data from input used as a filter text.</p>
  
  <p>here is my hostlistener in the directive:</p>
  
  <pre><code>@HostListener('input', ['$event.target.value'])
    public onChangeFilter(event: any): void {
      console.log('input event fired, value: ' + event);
      this.columnFiltering.filterString = event;
      this.filterChanged.emit({filtering: this.columnFiltering});
    }
  </code></pre>
  
  <p>this code is working perfectly, I am unable to unit test the same.</p>
  
  <p>I have subscribed to the filterChanged EventEmitter, in my unit test to check the value. </p>
  
  <p>I tried simulating keypress event to change value and also tried settings value attribute. None of these is working for me.</p>
  
  <p>here is my spec file:</p>
  
  <pre><code>describe('Table View', () =&gt; {
    let fixture: ComponentFixture&lt;any&gt;;
      let context: TableComponent;
     beforeEach(() =&gt; {
       TestBed.configureTestingModule({
            providers: [
              TableComponent,
            ],
            imports: [TableModule],
        });
        fixture = TestBed.createComponent(TableComponent);
        context = fixture.componentInstance;
      });
  it('should allow filter', () =&gt; {
        const element = fixture.nativeElement;
        context.config = config;
        fixture.detectChanges();
  
        let tableChangeCount = 0;
        let tableEvent: any;
        context.tableChanged.subscribe((event: any) =&gt; {
          tableChangeCount++;
          tableEvent = event;
        });
        // Check if table exists
        let inputElement = element.querySelectorAll('tr')[1].querySelector('input');
      let e = new KeyboardEvent("keypress", {
              key: "a",
              bubbles: true,
              cancelable: true,
            });
            inputElement.dispatchEvent(e);
   });
  
  });
  </code></pre>
  
  <p>I tried setting value:</p>
  
  <pre><code>let attrs = inputElement.attributes;
        inputElement.setAttribute('value', 'abc');
         for (let i = attrs.length - 1; i &gt;= 0; i--) {
           // Attribute value is set correctly
           if (attrs[i].name === 'value') {
           console.log(attrs[i].name + "-&gt;" + attrs[i].value);
           }
         }
  </code></pre>
  
  <p>Can anyone please help me, how can I unit test the same?</p>