2

I am trying to create a test for material-ui slider. Able to find slider options but fireEvent.click() does not trigger onChange event. Example is in here: https://codesandbox.io/s/material-demo-y62ks

2 Answers 2

0

I'm late to the party, but for some people.

Use fireEvent.mouseDown(option1); it should work, I tested it in codesanbox link.

For future people also want to test slider please see my answer: Testing a material ui slider with @testing-library/react

Sign up to request clarification or add additional context in comments.

Comments

0

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.

userEvent best simulates the user's action. You can import it from "@ testing-library / user-event".

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.