首页 > 解决方案 > 在笑话酶中按名称查找组成元素

问题描述

零件:

<input name="search" onChange={this.onChange}>

console.log(component.find('div').at(0).childAt(0).find('input').find('search').debug())

错误:

不显示任何东西

标签: reactjsjestjsenzymebabel-jest

解决方案


您可以通过指定称为Object Property Selector的属性来查找组件。请在此处查找详细信息。

正如您所说,您想使用name属性查找组件,然后请尝试以下操作:

component.find({ name: "search" }).debug();

推荐阅读