简体   繁体   English

反应测试库 material-ui slider

[英]react-testing-library material-ui slider

I am trying to create a test for material-ui slider.我正在尝试为 material-ui slider 创建一个测试。 Able to find slider options but fireEvent.click() does not trigger onChange event.能够找到 slider 选项但fireEvent.click()不会触发onChange事件。 Example is in here: https://codesandbox.io/s/material-demo-y62ks示例在这里: https://codesandbox.io/s/material-demo-y62ks

I'm late to the party, but for some people.我参加聚会迟到了,但对某些人来说。

Use fireEvent.mouseDown(option1);使用fireEvent.mouseDown(option1); it should work, I tested it in codesanbox link.它应该可以工作,我在codesanbox链接中对其进行了测试。

For future people also want to test slider please see my answer: Testing a material ui slider with @testing-library/react对于未来的人也想测试 slider 请看我的回答: Testing a material ui slider with @testing-library/react

Whenever you are testing MUI components, you must use userEvent, instead of fireEvent, because most MUI components do not use "standard" functions like onClick to trigger their events.每当您测试 MUI 组件时,您必须使用 userEvent,而不是 fireEvent,因为大多数 MUI 组件不使用像onClick这样的“标准”函数来触发它们的事件。

userEvent best simulates the user's action. userEvent 最能模拟用户的动作。 You can import it from "@ testing-library / user-event".您可以从“@ testing-library / user-event”导入它。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 react-testing-library 测试 material-ui 数据网格时出现问题 - Problem testing material-ui datagrid with react-testing-library 使用带有 material-ui 的 react-testing-library 的问题 - issue working with react-testing-library with material-ui 如何使用 react-testing-library 检查 material-ui MenuItem 是否被禁用 - How to check if a material-ui MenuItem is disabled using react-testing-library 如何使用react-testing-library测试withStyles中包含的样式化的Material-UI组件? - How to test styled Material-UI components wrapped in withStyles using react-testing-library? react-testing-library + material-ui 错误:元素类型无效: - react-testing-library + material-ui error: Element type is invalid: 反应。 Fromik。 Material-ui表单提交事件测试使用react-testing-library失败 - React. Fromik. Material-ui form submit event testing fails using react-testing-library 在使用 react-testing-library 进行测试期间,单击两次 material-ui 图标不会将其颜色更改为默认值 - Clicking twice material-ui icon does not change its color to default during tests with react-testing-library Material-UI 表单和反应测试库所需的表单字段 - Material-UI Form and React Testing Library Required Form Fields React-Testing 库未在快照中呈现 Material-UI 对话框 - React-Testing library not rendering Material-UI Dialog in snapshot 如何在 React 测试库中获取 Material-UI 密码输入 - How to get a Material-UI password input in React Testing Library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM