Is there a way to write unit test cases for the private function of a component?
Here is my function,
private scrollToFirstInvalidControl() {
const firstInvalidControl: HTMLElement = this.el.nativeElement.querySelector(
"form .ng-invalid"
);
firstInvalidControl.focus(); //without smooth behavior
}
Yes, it is possible to write unit test cases for the private function of the component.
for your method, it will be tested as
beforeEach(() => {
fixture = TestBed.createComponent(AuthContainerComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should go to error field', () => {
// arrange
...
// act
(component as any).scrollToFirstInvalidControl();
//assert
....
});
pre
& code
tags ):