如何使用茉莉花来测试如何测试角形的第一形式控制,重点是页面加载

时间:2018-12-18 07:33:00

标签: angular jasmine protractor

使用上下文加载页面后,我正在使用以下代码将重点放在第一个输入字段上

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字段加载表单

1 个答案:

答案 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();
})