question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

selectEvent.select not working after updating to react 18

See original GitHub issue

after 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:closed
  • Created a year ago
  • Reactions:4
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

7reactions
morganr1commented, Apr 13, 2022

@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.

const advertiserInput = document.getElementById('react-select-2-input');
await selectEvent.openMenu(advertiserInput);
await selectEvent.select(advertiserInput, 'Tony');

Seems like its not playing nicely with the selectors of RTL 😞

Hope this helps m8!

1reaction
romgaincommented, May 4, 2022

@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 😀

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found