【问题标题】:Testing forms: angular2 testing测试形式:angular2测试
【发布时间】:2017-03-09 07:01:37
【问题描述】:

我正在尝试测试已导入“FormGroup”和“FormBuilder”的组件,但是当我尝试为该组件运行测试文件时,它给了我一个错误,提示“FormGroup”和“FormBuilder”是不是已知的形式属性。我试着做这样的事情,

TestBed.configureTestingModule({
imports: [ ],
declarations: [ FormComponent ],
providers: [ FormGroup, FormBuilder ]
})

然后它给出了以下错误:

Uncaught Failed: Can't resolve all parameters for FormGroup: (?, ?, ?).
Error: Can't resolve all parameters for FormGroup: (?, ?, ?).

那么如何在测试(spec)文件中导入formgroup和formbuilder呢?

我正在使用的 Angular 版本:2.1.0

【问题讨论】:

    标签: angular angular2-testing


    【解决方案1】:

    它给了我一个错误,说“FormGroup”和“FormBuilder”不是表单的已知属性。

    与您将ReactiveFormsModule 导入应用程序模块的方式相同,您需要在测试模块中执行相同的操作

    TestBed.configureTestingModule({
      imports: [ ReactiveFormsModule ],
      declarations: [ FormComponent ]
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-31
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多