【发布时间】:2022-11-10 22:01:53
【问题描述】:
我正在使用react-select 库为我的下拉可搜索组件创建一个测试。
在自定义react-select documentation 中定义的组件时,我无法将data-testid 属性添加到Option 组件。
data-testid 属性不会显示在 Option 元素的 DOM 中。
选项组件
import Select, { components } from 'react-select';
const CustomOption = (props: OptionProps<SearchDropdownOption, false>) => (
<components.Option {...props} data-testid="test-id" />
);
例如我有一个成功使用 Input 组件搜索下拉列表和 data-testid 属性在 DOM 中显示:
输入组件
import Select, { components } from 'react-select';
const CustomInput = (props: InputProps<SearchDropdownOption, false>) => (
<components.Input {...props} data-testid="test-id" />
);
而不是在Select 组件中使用它:
<Select<SearchDropdownOption, false>
components={{
Input: CustomInput,
Option: CustomOption,
}}
isSearchable={isSearchable}
/>
【问题讨论】:
标签: reactjs testing components react-select