I am trying to unit test resetform() function [used as TemplateVar.resetForm()] where loginVar is used as template variable for template driven form in angular. I am not getting any sources oridea ho to do that. Please guide. Thanks in advance!
component.html
<form #loginVar="ngForm">
```code form fields```
</form>
<button mat-raised-button color="primary" (click)="onReset(loginVar)">Reset</button>
component.ts
onReset(e) {
e.resetForm();
}
it('should reset form', () => {
const debugElement = fixture.debugElement;
const form: NgForm = debugElement.children[0].injector.get(NgForm);
const spy = spyOn(form, 'resetForm');
component.ClearForm(form);
expect(spy).toHaveBeenCalled();
});
This worked!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.