Complete the code to import the testing module needed for reactive forms.
import { ReactiveFormsModule } from '@angular/forms'; import { TestBed } from '@angular/core/testing'; TestBed.configureTestingModule({ imports: [[1]] });
You need to import ReactiveFormsModule to test reactive forms in Angular.
Complete the code to create a form control with an initial empty value.
import { FormControl } from '@angular/forms'; const nameControl = new FormControl([1]);
To start with an empty string value in a form control, use ''.
Fix the error in the test to simulate a user typing 'hello' into an input element.
const input = fixture.nativeElement.querySelector('input'); input.value = [1]; input.dispatchEvent(new Event('input')); fixture.detectChanges();
The value assigned to input.value must be a string literal, so it needs quotes like 'hello'.
Fill both blanks to check if the form control is valid and touched after user interaction.
expect(component.form.get('email')?.[1]).toBeTruthy(); expect(component.form.get('email')?.[2]).toBeTruthy();
After user input, the form control should be valid and touched.
Fill all three blanks to simulate a button click and verify the form submission method is called.
const button = fixture.nativeElement.querySelector('button'); button.[1](); expect(component.[2]).toHaveBeenCalled(); fixture.detectChanges(); expect(component.form.[3]).toBeTruthy();
The button is clicked with click(), the onSubmit method should be called, and the form should be valid.