使用上下文加载页面后,我正在使用以下代码将重点放在第一个输入字段上
this.el.nativeElement.querySelectorAll('input')[0].focus();
如何通过单元测试和e2e的角度6来测试场是否集中
component.modelForm = new ModelForm(null, {});
component.form.addControl('test', new FormControl(null));
component.form.addControl('test1', new FormControl(null));
fixture.detectChanges();
console.log(fixture.debugElement.queryAll(By.css('input')))
我正在如上所述的单元测试中添加formcontrols。
并且html组件将为“
基于输入字段,我将使用formcontrol字段加载表单
答案 0 :(得分:0)
您可以做的是,检查是否在该特定focus
元素上调用了input
方法。为此,您必须监视inputEl.focus()
it('Input el should be focused', () => {
let inputEl = comp.el.nativeElement.queryAll(By.css('input'))[0];
spyOn(inputEl ,'focus');
comp.ngOnInit();
expect(inputEl.focus).toHaveBeenCalled();
})