Testing a Form
Learn how to write tests for forms.
We'll cover the following
Testing strategy
There are two ways to create forms in Angular:
-
The simplest way is creating the template-driven form, where we define all our form inputs in the component template. We populate the form inputs with initial values and allow the user to enter or amend the values. Then, when we submit the form, we simply gather the input values and send them to the server.
-
The second approach is creating a reactive form driven by the component script. When we receive our initial data from the service, we make a copy of that data, which we use to populate the form inputs. We allow the user to enter data into the form. Finally, when we are ready to submit the form, we copy the input values back to our component and submit a copy of the data.
Get hands-on with 1200+ tech skills courses.