首页 > 解决方案 > TypeError:form.updateValueAndValidity 不是 Angular 中的函数

问题描述

我正在尝试测试这些方法,但收到此错误:TypeError: form.updateValueAndValidity is not a function

onGoToStep(step: string): void {
    this.activeStepIndex =
      step === 'prev' ? this.activeStepIndex - 1 : this.activeStepIndex + 1

    this.onSetForm()
  }

onSetForm(): void {
  this.masterForm.map(form => form.updateValueAndValidity())
}

这是我的spec.ts

describe('onGoToStep', () => {
    it('makes expected calls', () => {
      spyOn(component, 'onSetForm').and.callThrough();
      component.masterForm = ['']
      fixture.detectChanges()
      component.onGoToStep('prev');
      expect(component.onSetForm).toHaveBeenCalled();
    });
  });

显然问题出在form我不知道如何绕过它。

有没有办法解决这个问题?

标签: javascriptangulartypescripttestingkarma-jasmine

解决方案


推荐阅读