Angular 2表单(ViewChild)控件在单元测试中为空

时间:2018-01-19 14:01:33

标签: angular forms unit-testing

模板HTML:

@ViewChild('myForm') myForm: NgForm;

组件有:

fixture.debugElement.componentInstance.myForm.controls

在我的测试中,当我在console.log中进行以下操作时,我得到{}

errors: null

表单也有status 'VALID'<div> <label for="Authentication">Authentication:</label> <span class="spacer"> <input type="text" name="Authentication" id="-Authentication" /> </span> <span class="short_help">Authentication type, I, II, or III</span> </div> <br/> <div> <label for="Branch">Branch:</label> <span class="spacer"> <input type="text" name="Branch" id="Branch" /> </span> <span class="short_help">Which regional branch.</span> </div> <br/> <div> <label for="Persistent">Persistent:</label> <span class="spacer"> <input type="checkbox" name="Persistent" id="Persistent" /> </span> <span class="short_help">Persistent connection</span> </div> ,尽管表单应包含无效的FormControl。使用ViewChild而不是FormBuilder配置测试表单是否可能?有没有办法用我的ViewChild设置呢?

0 个答案:

没有答案