【发布时间】:2017-02-07 09:57:27
【问题描述】:
我的 angular2 单元测试代码因以下回溯而失败。我知道这是因为没有将 formControlName 属性添加到 FormGroup 内的 input 标记中。
但我在该特定标签中添加了[ngModelOptions]="{standalone: true}"。
<md-slide-toggle [(ngModel)]="isAvailable" color="primary" [ngModelOptions]="{standalone: true}">
</md-slide-toggle>
它在主站点中完美运行,但在测试时,它显示
PhantomJS 2.1.1 (Linux 0.0.0): Executed 39 of 65 (1 FAILED) (0 secs / 1.391 secs)
PhantomJS 2.1.1 (Linux 0.0.0) VehicleFormComponent should create FAILED
Error: Error in ./VehicleFormComponent class VehicleFormComponent - inline template:41:63 caused by: No value accessor for form control with unspecified name attribute in src/test.ts (line 98781)
_throwError@webpack:///~/@angular/forms/src/directives/shared.js:122:0 <- src/test.ts:15986:48
【问题讨论】:
标签: javascript unit-testing angular angular2-template