title: Why is change event for reactive form control not firing in Jasmine Angular unit test?
body: <p>I have a change function I am passing to the change event for a <strong>reactive form control</strong> that evaluates the <strong>dirty</strong> state and to check if there are any errors on the control and if so then set a boolean flag to true/false.  This boolean flag is then used to determine whether or not to show a <code>&lt;div&gt;</code> element that has an error message.  This works just fine in the browser, but when the unit test runs, the "dirty" is never being set to true.  Here is my code:</p>
  
  <p><strong>HTML</strong></p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;form [formGroup]="myForm" novalidate&gt;
      &lt;input id="age" formControlName="age" (change)="onChange()" /&gt;
      &lt;div id="ageError" *ngIf="ageIsError()"&gt;
          &lt;label&gt;Age has errored&lt;/label&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Component</strong></p>
  
  <pre><code>constructor(private fb: FormBuilder) {}
  
  ngOnInit() {
      this.myForm = this.fb.group({
          age: [null, [Validators.min(18)]]
      });
  }
  
  onChange() {
      if (this.ageIsError())
          // do something
  }
  
  ageIsError() {
      return this.myForm.controls.age.hasError('min') &amp;&amp;
             this.myForm.controls.age.dirty;
  }
  </code></pre>
  
  <p><strong>Unit Test</strong></p>
  
  <pre><code>it('should show error message when age is less than 18', fakeAsync(() =&gt; {
      let age = component.myForm.controls.age;
      age.setValue('10', { emitEvent: true });
      fixture.detectChanges();
  
      fixture.whenStable().then(() =&gt; {
          let ageError = debugElement.query(By.css('#ageError')).nativeElement;
          expect(component.ageIsError()).toBe(true);
          expect(ageError.innerText).toContain('Age has errored');
      });
  }));
  </code></pre>
  
  <p>Again, the actual implementation works in the browser, but the unit test fails.  Does anyone know hoe to emit the event in jasmine to set the control to a dirty state, or is there a better way to achieve this?  Thanks!</p>