Open illright opened 2 years ago
I would be willing to implement this feature with some guidance
The problem with utility APIs like selectOptions
is that they define the interaction by the effect. The user can achieve that effect by different means. So there isn't a single truth of desired behavior that we could check the implementation against.
An <input type="range"/>
can be changed per keyboard or per pointer - per different keys and movements. I'd rather implement the behavior on those events than introduce a new utility.
Then interacting with the control in the test gives confidence that a user can actually change the value.
Keyboard interaction should be easy to implement. ArrowLeft
, ArrowRight
, Home
, End
, PageUp
, PageDown
, anything else?
Pointer interaction might be more tricky as the pointer position corresponds with a value based on the control dimensions. And possibly how the control is displayed by different browsers?
In testing environments without layout (JSDOM), this might be tricky. But we might also just view that problem as out of scope and rely on the user to set the necessary element properties in such environment.
In the meantime, this works fine:
import { fireEvent } from '@testing-library/dom'; // or `@testing-library/react`
// ...
const slider = container.querySelector('input[type="range"]')!;
fireEvent.change(slider, { target: { value: 170 } });
But it would be cool to see support for this in @testing-library/user-event
as well.
I've tried using .click(element)
to give the focus to the element and then using .keyboard()
with arrow keys but it's currently throwing an error as described here https://github.com/testing-library/user-event/issues/901 😅
Meanwhile, we can achieve this with fireEvent like @illright says, in my case I used
const slider = screen.getByRole('slider');
await fireEvent.update(slider, '5');
+1 to get support for this
+1 to get support for this
Hi there! if there are plans to integrate <input type="range">
support within userEvent
. It would be incredibly helpful for more precise testing scenarios. Any updates or insights on this would be much appreciated. Thanks a lot!"
Problem description
I want to test that my
<input type="range">
calls the necessary function upon moving the slider thumb to a particular value. So far, it doesn't seem to be possible with the current capabilities ofuser-event
.Suggested solution
Similarly to
selectOptions
, I would like to have something like this:Other ideas for the name could be
dragTo
,moveSliderTo
.Additional context
No response