[DropdownMenu] `jest` / `react-testing-library` tests failing on `@radix-ui/react-dropdown-menu` after upgrade
See original GitHub issueBug report
Current Behavior
Went from "@radix-ui/react-dropdown-menu": "0.1.4", to "@radix-ui/react-dropdown-menu": "0.1.6", and the tests were working on 0.1.4.
Actually, any test that involves some sort of pop up box appearing currently fails (so "@radix-ui/react-dropdown-menu": "0.1.6" and "@radix-ui/react-dialog": "0.1.7", for me).
My current test looks like this (there’s more of it inside my CodeSandbox example down below)
test('BulkActions dropdown gets clicked and shows content', () => {
userEvent.click(screen.getByTestId(bulkActionsDropdownName))
expect(screen.queryByTestId(dropdownContentName)).toBeInTheDocument()
})
Output looks like this
FAIL src/components/BulkActions/bulk-actions.test.tsx
✓ BulkActions gets rendered (20 ms)
✕ BulkActions dropdown gets clicked and shows content (23 ms)
● BulkActions dropdown gets clicked and shows content
expect(received).toBeInTheDocument()
received value must be an HTMLElement or an SVGElement.
Received has value: null
39 | userEvent.click(screen.getByTestId(bulkActionsDropdownName))
40 |
> 41 | expect(screen.queryByTestId(dropdownContentName)).toBeInTheDocument()
| ^
42 | })
43 |
This was a passing test using "@radix-ui/react-dropdown-menu": "0.1.4". Seems like the userEvent.click isn’t getting triggered
Expected behavior
Having not changed anything within my code except for upgrading the dependency, I expect the test to pass
Reproducible example
Suggested solution
No idea, I don’t even understand what’s happening, really
Additional context
Nothing to add
Your environment
| Software | Name(s) | Version |
|---|---|---|
| Radix Package(s) | @radix-ui/react-dropdown-menu | 0.1.6 |
| React | n/a | 17.0.2 |
| Browser | Chrome | Version 98.0.4758.80 |
| Assistive tech | - | - |
| Node | n/a | v14.19.0 |
| npm/yarn | yarn | 1.22.17 |
| Operating System | MacOS | 11.2.3 |
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:5
Top Results From Across the Web
react testing library assert dropdown options are rendered in ...
I'm trying to test a dropdown component rendering certain options in ... core tenets of react-testing-library is that we want our tests to ......
Read more >radix dropdown tests - CodeSandbox
@radix-ui/react-dropdown-menu. 0.0.6 · @stitches/react. 0.0.3-canary.4 (0.0.3-canary.4) · @testing-library/jest-dom. 5.11.9 · @testing-library/react. 11.2.3 · @ ...
Read more >How to test a Semantic UI React Dropdown using Jest and ...
A Semantic UI React Dropdown using the options array above. Give it a default value of the first option in the array, Jenny...
Read more >How to test dropdown component with React Testing Library
Hi, I am trying to test a dropdown component with React Testing Library. I need to set the value of the component, but...
Read more >[Solved]-React Testing Library + Material UI DropDown-Reactjs
test ("select", async () => { render(<App />); // Get and click in the dropdown const dropdownButton = screen.getByRole("button", { name: /dog name...
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
Related: https://github.com/radix-ui/primitives/issues/856
Sorry for the delay responding here. You’re seeing this because the event bindings were adjusted in the recent version and now exclusively bind to
PointerEvent, where before they also usedonClick.JSDOM doesn’t currently support
PointerEvent, and thus testing-library can’t provide the correct properties on the Event.Providing you’re using
user-event, testing lib should be firingPointerEvents, but you’ll need to provide your own implementation to be able to test with the expected properties:The above sets some properties to mock a “mouse left click” by default, you can pass your own properties inline too when needed:
I’ll make a note to add something about this in our documentation as it is quite a common issue, hopefully the above helps though. I’m going to close the issue now but feel free to follow up if you have any other questions 🙏
@andy-hook , that did the trick! Thank you for your elaborate and informative answer! 🤘