JedWatson / JedWatson/react-select
Menu is closing inside tests
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 28k
- Forks
- 4.1k
- PR merge metrics
- No merged PRs in 30d
Description
<AsyncReactSelect
defaultOptions
loadOptions={async () => [
{ value: "Pear", label: "Pear" },
{ value: "Banana", label: "Banana" },
{ value: "Raspberry", label: "Raspberry" },
]}
closeMenuOnSelect={false}
isMulti
onMenuClose={() => {
console.log("called the close!!")
}}
/>
In the browser is fine. I select an option, menu stays open and option populates into select
In my tests however it seems to close at this point
await act(async () => {
// assert option not selected yet
expect(screen.queryByLabelText("Remove Dr Jimmy Carter")).toBe(null)
// open the dropdown
const selectDropdown = screen.getAllByRole("combobox")[0]
await userEvent.click(selectDropdown)
await screen.findByText("Pear")
await userEvent.keyboard("{enter}")
await screen.findByLabelText("Remove Pear")
screen.debug()
})
I notice that this line await userEvent.keyboard("{enter}") correctly selects the option but closes the menu. I verified this by seeing "called the close!!" being called in my tests. This is only called in the browser when I click outside (as expected). Anything wrong in the component or is it the testing library?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the shown AsyncReactSelect test and the userEvent.keyboard("{enter}") interaction, then compare the test result with browser behavior. Reproduce whether selecting Pear triggers onMenuClose and closes the menu despite closeMenuOnSelect={false}; done means the option is selected while the menu remains open and the close callback is not called.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100