Skip to content
Advertisement

Trouble unit testing angular reactive form control reset from button click

I am facing an issue to write an unit test case in jasmine for my angular application. Have a reactive form and trying to reset a particular form control from a button click. Even though the scenario should be simple enough to test, it seems that I am missing something here.

Below is the code snippet from the app.

app.component.html:

JavaScript

app.component.ts

JavaScript

Unit test code

JavaScript

Angular: 10.0.14

Angular CLI: 10.0.8

StackBlitz: https://angular-ivy-fc6rik.stackblitz.io

Advertisement

Answer

seems like you mocked clearField. Add this to actually execute its content when you mock it:

JavaScript

So everytime clearField is called, it will trigger the spy (so you know if it has been called), and will execute its content .

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement