ionic-framework - 在测试中未为 ionic 输入呈现输入

标签 ionic-framework ionic4

我有一个包含两个字段的简单表单:用户名和电子邮件。我的测试是这样的:

...
fit('should create', () => {
    console.log(fixture.debugElement.nativeElement.childNodes);
    expect(component).toBeTruthy();
  });
....

我刚刚添加了 console.log到生成的规范文件。从下面的输出可以看出, ionic 输入元素不包含输入元素。你知道为什么吗? (我需要它来运行附加到输入的模糊处理程序)
LOG: NodeList{0: <form _ngcontent-a-c0="" novalidate="" ng-reflect-form="[object Object]" class="ng-untouched ng-pristine ng-invalid"><div _ngcontent-a-c0=""><!--bindings={
  "ng-reflect-ng-if": "false"
}--><ion-item _ngcontent-a-c0="" class="ion-untouched ion-pristine ion-invalid"><!--bindings={
  "ng-reflect-ng-if": "true"
}--><ion-label _ngcontent-a-c0="" color="medium" position="floating" ng-reflect-color="medium" ng-reflect-position="floating">Username</ion-label><!--bindings={
  "ng-reflect-ng-if": "false"
}--><!--bindings={
  "ng-reflect-ng-if": "false"
}--><!--bindings={
  "ng-reflect-ng-if": "false"
}--><!--bindings={
  "ng-reflect-ng-if": "false"
}--><!--bindings={
  "ng-reflect-ng-if": "false"
}--><ion-input _ngcontent-a-c0="" formcontrolname="username" type="text" ng-reflect-type="text" ng-reflect-name="username" class="ng-untouched ng-pristine ng-invalid ion-untouched ion-pristine ion-invalid"></ion-input></ion-item><ion-item _ngcontent-a-c0="" class="ion-untouched ion-pristine ion-valid"><!--bindings={
  "ng-reflect-ng-if": "true"
}--><ion-label _ngcontent-a-c0="" color="medium" position="floating" ng-reflect-color="medium" ng-reflect-position="floating">Email</ion-label><!--bindings={
  "ng-reflect-ng-if": "false"
}--><ion-input _ngcontent-a-c0="" formcontrolname="email" readonly="true" type="email" ng-reflect-readonly="true" ng-reflect-type="email" ng-reflect-name="email" class="ng-untouched ng-pristine ng-valid ion-untouched ion-pristine ion-valid"></ion-input></ion-item><ion-input _ngcontent-a-c0="" formcontrolname="token" type="hidden" ng-reflect-type="hidden" ng-reflect-name="token" class="ng-untouched ng-pristine ng-invalid ion-untouched ion-pristine ion-invalid"></ion-input></div><div _ngcontent-a-c0="" class="ion-padding-top"><ion-button _ngcontent-a-c0="" expand="block" size="large" type="submit" ng-reflect-disabled="true" ng-reflect-expand="block" ng-reflect-size="large" ng-reflect-type="submit">Register</ion-button></div></form>}

最佳答案

您可以使用:

await element(by.css('ion-input[formControlName="something"] input'))

获取可以与之交互的 ionic 输入的输入。

关于ionic-framework - 在测试中未为 ionic 输入呈现输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62029308/

相关文章:

css - 以模式显示滚动

ionic-framework - 如何添加 svg 自定义图标 ionic 2

ionic-framework - 如何在 ionic 中调整卡片的长度?

ios - ionic 4 : The "src" content of an "img" tag is not updating when I change it from the controller in IOS

ionic-framework - Ionic - 应用程序启动时闪烁错误的起始页面

javascript - Ionic-1 导航

ionic-framework - Ionic2 - 登录然后侧边菜单

ionic-framework - ionic 4 - 警报 Controller : Property 'present' does not exist - Angular?

angular - 如何修复 router.navigate 后未触发的 ngOnInit()

ionic4 - Ionic 4 CLI无法生成服务