Questions about testing events with the user-event utility.
Questions tagged [user-event]
65 questions
2
votes
1 answer
Testing MUI5 Select with testing-library
I'm using create-react-app 5 (with React 17, Jest, and testing-library), along with MUI 5. I'd like to test clicking a simple Select menu, and making sure the menu options appear. I tried the following:
it('shows the menu', async () => {
…

JW.
- 50,691
- 36
- 115
- 143
2
votes
0 answers
How can I use FireEvent's touchStart option in userEvent
I'm studying test using jest, and React testing-library.
I have a question about userEvent.
There is a touchStart option in fireEvent.
How can I use touchStart option in userEvent.
fireEvent.touchStart(screen.getByRole('button'));
Please let me know

ezdar
- 45
- 5
1
vote
1 answer
Cannot find module '@testing-library/dom' from 'node_modules/@testing-library/user-event/dist/click.js' Require stack:
In a project we recently started using userEvent instead of fireEvent but now we are getting this issue
FAIL src/modules/DashboardHeader/index.test.tsx
● Test suite failed to run
Cannot find module '@testing-library/dom' from…

paraS elixiR
- 1,866
- 1
- 18
- 26
1
vote
1 answer
Is the `user-event` library compatible with React Native Testing Library?
Can anyone confirm whether the user-event library is compatible with React Native Testing Library?
I'm guessing not, as the user-event docs say
the library can be used with any framework as long as there is a DOM
and the React Native Testing…

Andrew
- 3,825
- 4
- 30
- 44
1
vote
1 answer
testing library userEvent.selectOptions does not select option
I have a React component which renders a combobox (another external component) with an option. When deployed the component does work as expected.

pcvnes
- 927
- 2
- 15
- 41
1
vote
1 answer
arrows up and down don't work with userEvent
I'm handling a test on input type number, where I expect increase and decrease value when typing on keyboard arrow up and down respectively. The Issue is that nothing happens, the input value remains the same. Someone could look into my code and see…

Wilson Medeiros Jr.
- 26
- 3
1
vote
1 answer
How can I use number Value in react-testing-library userEvent
Recently, I am changing fireEvent to userEvent. If the type value of userEvent is number, a type error occurs, but is it not possible to use the number type for the value in userEvent?
await userEvent.type(
screen.getByRole('textbox', { name:…

ezdar
- 45
- 5
1
vote
0 answers
successive userEvent.type on the same input does not behave as expected
i'm trying to test a react component with react/testing-library:
This is my test:
const startDate = document.querySelector('#startDate') as HTMLInputElement;
await userEvent.type(startDate, '11/07/2022');
await userEvent.type(startDate,…

JULIEN PICARD
- 1,364
- 1
- 8
- 11
1
vote
1 answer
Jest: TypeError: Cannot read properties of undefined (reading 'getFileName')
I recently started using the @testing-library/user-event library and I am facing a lot of issues. I am trying to test a textbox validation flow however I am getting the error
TypeError: Cannot read properties of undefined (reading 'getFileName')
…

Ayushi
- 31
- 1
- 3
1
vote
0 answers
userEvent.type adds back previously typed characters after asserting input value is empty, and typing new values
so I had written a sample test case for an input, where if I press enter it clears the input field. It works till this point, but when I try to type after that, somehow the previously typed text comes back as part of the input value, and it's…

lanxion
- 1,350
- 1
- 7
- 20
1
vote
2 answers
How Can I Test an MUI ToggleButtonGroup with a userEvent?
I am using MUI ToggleButtonGroup component like so:

CodeFinity
- 1,142
- 2
- 19
- 19
1
vote
1 answer
React-Select & User-Event Library
I would like to test my react-select component using User-Event-Testing-Library (https://testing-library.com/docs/ecosystem-user-event/).
I just want to test if select open the menu if clicked.
Here is my code:
If I use fireEvent it works, however…

Theo Cerutti
- 779
- 1
- 10
- 33
1
vote
2 answers
fireEvent.click() (form fireEvent) vs element.click() (from JSDOM)
Context: I'm using Testing Library and trying to understand some of the underlying mechanisms.
As JSDOM already provides the handling of the "click" event, I was wondering:
Is there a difference between these two ways of managing the event?
If not,…

JRO
- 13
- 5
1
vote
1 answer
How can I simulate window.focus() with react testing-library?
I've been doing a lot of research, and I can't find a way to successfully simulate a window focus event.
I looked through "testing-library/user-event" and still can't find a way to do this.
In my component, we have window.addEventListener('focus',…

neaumusic
- 10,027
- 9
- 55
- 83
1
vote
2 answers
How to test react-jsonschema-form components with @testing-library/user-event
I faile to write even the most simple tests for react jsonschema form. Because changes to input elements seem not to be reflected in the dom.
Given a minimal form like this:
const schema = {
title: "Todo", type: "object",
properties: {
…

max
- 29,122
- 12
- 52
- 79