我是反应测试库的新手,所以这可能很容易,但我目前有一个从 fluent UI 导入的下拉列表,并且当我尝试测试它时当前收到“元素没有值设置器”错误使用反应测试库。这是我的渲染功能。
import { Dropdown, IDropdownStyles, IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
import { Stack } from 'office-ui-fabric-react/lib/Stack';
render()
{
return (
<div className="LandingPage">
<h3>Here are some options</h3>
<form onSubmit={this.handleSubmit}>
<Stack>
<Stack.Item align="center">
<Dropdown
placeholder="Select an option"
label="Select an option"
options={this.options}
styles={this.dropdownStyles}
onChange={this.handleChange}
data-testid="myId"
/>
</Stack.Item>
</Stack>
</form>
</div>
);
}
}
这是失败的行:
const dropdownOption: IDropdownOption = {
key: "0",
text: "dropdownOption"
}
fireEvent.click(queryByTestId("myId"), { target: { value: 'B' }, option: dropdownOption })
The given element does not have a value setter
> 44 | fireEvent.click(queryByTestId("myId"), { target: { value: 'B' }, option: dropdownOption })
| ^