selectEvent.select not working after updating to react 18
See original GitHub issueafter updating to react 18 the following test is failing
it('testing selecting item', async () => {
const onChangeSpy = jest.fn();
const options = [
{
value: 1,
label: 'One',
},
{
value: 2,
label: 'Two',
},
];
render(<Select options={options} value={undefined} label="Label" inputId="id" onChange={onChangeSpy} />);
await selectEvent.select(screen.getByLabelText('Label'), ['Two']);
expect(onChangeSpy).toHaveBeenCalledWith(options[1], expect.any(Object));
});
The error message is
Unable to find an element with the text: Two. This could
be because the text is broken up by multiple elements.
In this case, you can provide a function for
your text matcher to make your matcher more flexible.
Issue Analytics
- State:
- Created a year ago
- Reactions:4
- Comments:9 (3 by maintainers)
Top Results From Across the Web
react-select-event doesn't trigger the onChange function to set ...
The issue was solved by changing the container to container: () => document.body.querySelector('[class$=-menu]').
Read more >react-select-event - npm
Start using react-select-event in your project by running `npm i react-select-event`. There are 9 other projects in the npm registry using ...
Read more >react-select-event - Testing Library
react -select-event is a companion library for React Testing Library that provides helper methods for interacting with react-select elements.
Read more >user-select - CSS: Cascading Style Sheets - MDN Web Docs
Until now, Chromium has chosen to fix the issues to make the final behavior meet the specifications. Values. none. The text of the...
Read more >React Testing Library and the “not wrapped in act” Errors
I recently upgraded React and React testing library. ... Why? And how do I fix this? ... The following test will have the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@sindrisig Not sure but, this may or may not help you. I’ve recently updated my project from React 17 -> 18 using
react-select
+react-select-event
for testing as you’ve shown above.I found I had to use
openMenu
first before I could make a selection in certain scenarios (in my case using a react-select/creatable component).Also worth noting I had to select the target input via a good old fashioned
document.getElementById
method.Seems like its not playing nicely with the selectors of RTL 😞
Hope this helps m8!
@annidai I unfortunately don’t have time to work on this right now, but I will merge PRs if anyone else can contribute a fix 😀