有没有一种方法可以为组件的私有功能编写单元测试用例?
这是我的职能,
private scrollToFirstInvalidControl() {
const firstInvalidControl: HTMLElement = this.el.nativeElement.querySelector(
"form .ng-invalid"
);
firstInvalidControl.focus(); //without smooth behavior
}
是的,可以为组件的私有功能编写单元测试用例。
对于您的方法,它将被测试为
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 ):