我们能否在React js的笑话酶中按其名称找到组成元素

问题描述 投票:1回答:1

component:

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

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

错误:

不显示任何内容

reactjs jestjs enzyme babel-jest
1个回答
0
投票

您可以通过指定组件的属性来找到它们,这些属性称为对象属性选择器。请查找详细信息here

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

component.find({ name: "search" }).debug();
© www.soinside.com 2019 - 2024. All rights reserved.