title: angular2 unit test: how to test events with triggerEventHandler
body: <p>I'm trying to write a unit test for <code>click</code> event with angular2 <strong>rc1</strong>. my component handles click event with <code>onClick()</code> method and changes <code>name</code> field from <code>bar</code> to <code>foo</code>. see this <a href="https://plnkr.co/edit/VLSjLOwbzR9AaVd2ioHE?p=preview" rel="noreferrer">plunker</a>.</p>
  
  <p>Now I want to fire a <code>click</code> event to test whether <code>name</code> value is <code>bar</code> or not. please see <code>unit-testing.spec.ts</code> file on plunker. </p>
  
  <pre><code>it('should change name from foo to bar on click event', inject([], () =&gt; {
  return builder.createAsync(UnitTestingComponentTestController)
    .then((fixture: ComponentFixture&lt;any&gt;) =&gt; {
      let query = fixture.debugElement.query(By.directive(UnitTestingComponent));
      expect(query).toBeTruthy();
      expect(query.componentInstance).toBeTruthy();
  
      // fixture.detectChanges();
      expect(query.componentInstance.name).toBe('foo');
      query.triggerEventHandler('click',{});
      expect(query.componentInstance.name).toBe('bar');
      // fixture.detectChanges();
    });
  }));
  </code></pre>
  
  <p>And here is <code>UnitTestingComponentTestController</code></p>
  
  <pre><code>@Component({
  selector: 'test',
  template: `
  &lt;app-unit-testing&gt;&lt;/app-unit-testing&gt;
  `,
  directives: [UnitTestingComponent]
  })
  class UnitTestingComponentTestController {
  }
  </code></pre>
  
  <p>This test fails with this message:</p>
  
  <pre><code>Expected 'foo' to be 'bar'.
  </code></pre>
  
  <p>Here is the method signature for <code>triggerEventHandler()</code></p>
  
  <pre><code>triggerEventHandler(eventName: string, eventObj: any): void;
  </code></pre>
  
  <p><strong>My question is how can I fire an event and test it with angular2.</strong></p>
  
  <p>One solution might be to call <code>onClick()</code> method on <code>componentInstance</code> but in this case we just test <strong>internal</strong> of the class and not the <strong>component behavior</strong></p>