【发布时间】:2021-08-04 19:31:55
【问题描述】:
我正在尝试对材质 ui 自动完成组件进行测试,我在此 example 中使用相同的组件,我尝试从此 question 中解决问题,但我没有找到解决方法它。
我的测试代码如下,问题是我只得到我在输入中输入的城市,而不是第一个结果。我对其进行了一些测试,我认为它没有选择ArrowDown 和Enter 的可用选项。
// Autocomplete is the Autocomplete component from material ui
test("Autocomplete Test", async () => {
render(<Autocomplete />);
const autocomplete = screen.getByTestId("autocomplete");
const input = within(autocomplete).getByRole("textbox");
autocomplete.click();
autocomplete.focus();
fireEvent.change(input, { target: { value: "london" } });
fireEvent.keyDown(autocomplete, { key: "ArrowDown" });
fireEvent.keyDown(autocomplete, { key: "Enter" });
const inputt = within(autocomplete).getByRole("textbox");
console.log(inputt.value);
expect(inputt.value).toEqual("London");
});
【问题讨论】:
标签: reactjs testing material-ui react-testing-library