Angular - Forcing a reactive form to be valid in a unit test : <p>I am using Angular v4.4.4. In a component, after a button is clicked in the template, the form is saved assuming the reactive form is valid. Something like (pseudo-code):</p>

<pre><code>public onSave(): void {
    if (this.myForm.valid) {
        this._createFoo();
    }
}

private _createFoo(): void {
    this._fooService.createItem(this.foo).subscribe(result =&gt; {
        // stuff happens...
    });
}
</code></pre>

<p>In the related unit test I need to force the form to be valid so I can confirm the service is being called. Something like this:</p>

<pre><code>it('should create Foo', () =&gt; {
    const spy = spyOn(_fooService, 'createItem').and.callThrough();
    component.foo = new Foo();
    fixture.detectChanges();
    const bookButton = fixture.debugElement.query(By.css('#bookButton'));
    expect(bookButton !== null).toBeTruthy('missing Book button');
    bookButton.triggerEventHandler('click', null);
    expect(spy).toHaveBeenCalled();
});
</code></pre>

<p>This will fail because myForm is never set as valid.</p>

<p>In this particular case I do not want to give every input in the form a value. I just need to watch and see if the service subscription occurs. How can I force the form to be valid?</p>
