Testing forms
As we saw in Chapter 10, Collecting User Data with Forms, forms are an integral part of an Angular application. It is rare for an Angular application not to at least have a simple form, such as a search form. We have already learned that reactive forms are better than template-driven forms in many ways and are easier to test, so in this section, we will focus only on testing reactive forms.
Consider the following search.component.ts
file:
import { Component } from '@angular/core';
import { FormControl, FormGroup, Validators } from '@angular/forms';
@Component({
selector: 'app-search',
template: `
<form [formGroup]="searchForm" (ngSubmit)="search()">
<input type="text" placeholder="Username" formControlName="searchText">
<button type="submit" [disabled]="searchForm.invalid">Search</button>
</form>
...