如何向 FormGroup 模拟添加值

问题描述

我正在尝试为以下方法编写业力测试

addNewRule() {
    let nameAdded = this.formRuletypeGroup.get('controlId').value;
    let typeAdded = this.formRuletypeGroup.get('type').value;

    console.log('nameAdded ----->',nameAdded );
    console.log('typeAdded ----->',typeAdded );

    if (nameAdded == '' || typeAdded == null) {
      return;
    }

}

如何在我的测试中模拟这个,以便 nameAdded 和 typeAdded 有值?

这是我的尝试,但值始终为空

 component.formTypeGroup= formBuilder.group({ 
      nameAdded : new FormControl('Test Name',Validators.required),typeAdded : ['Sir',Validators.required]
    });

当我查看 ng 测试的日志时,我看到以下内容

HeadlessChrome 87.0.4280 (Windows 10.0.0): 执行了 2 of 44 SUCCESS (0 secs / 0.447 secs)

LOG: '--------------nameAdded -------------->',''

HeadlessChrome 87.0.4280 (Windows 10.0.0): 执行了 2 of 44 SUCCESS (0 secs / 0.447 secs)

LOG: '--------------typeAdded -------------->',''

提前致谢!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)