酶找不到道具的成分 [英] Enzyme is not finding component by props
问题描述
我正在用酶测试的组件如下:
I've got a component I'm testing with Enzyme that looks like the following:
<RichTextEditor name="name" onChange={[Function]} value="<p>what</p>" focus={false}>
<div className="rich-text-editor">
<div className="btn-group" role="group">
<StyleButton active={false} icon="fa-list-ul" label="UL" onToggle={[Function]} style="unordered-list-item">
// ...
我正在尝试像这样检测那里的StyleButton组件:
I'm trying to detect the presence of the StyleButton component there like so:
mount(<RichTextEditor />).find('StyleButton[label="UL"]')
但是不返回任何组件.我只能通过搜索字符串"StyleButton"来找到所有的StyleButtons,但找不到按属性查找的方法,包括仅靠使用属性选择器即可.
But no components are returned. I can find all the StyleButtons by just searching for the string "StyleButton" but I can't find by property, including just by using the property selector on its own.
我粘贴的第一个代码块来自安装RichTextEditor的调试输出,因此StyleButton肯定在那里.
The first code block I pasted up there is from the debug output of mounting the RichTextEditor, so the StyleButton is definitely there.
有什么想法吗?
谢谢.
推荐答案
在文档中,没有选项将组件名称与 props 混合:
In the docs there is no option to mix name of component with props:
- CSS选择器
- 组件构造器
- 组件显示名称
- 对象属性选择器
您可以使用 findWhere :
wrapper.findWhere(n => n.name() === 'StyleButton' && n.prop('label') === 'UL')
这篇关于酶找不到道具的成分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!