-
Notifications
You must be signed in to change notification settings - Fork 915
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Having issues testing DropdownMenu with React testing library #856
Comments
Hey @nirbenya as you say this appears to be a limitation in jsdom. We favour testing in a real browser environment for reasons such as this and to better match what a user experiences (see cypress tests for this component) In terms of RTL though, I did some brief searching to see if anything had changed lately and the proposed solution suggested in this issue worked for me when combined with I also recommend checking out the user-event library if you haven't already. |
I made this work by combining @benoitgrelard #420 and @andy-hook answers:
|
Hello 👋🏻 Sorry for bringing up closed issue, but @andy-hook was you able to make it work with user-event library? Currently I'm migrating from antd menu to radix-ui dropdown and a lot of my tests are falling now ) The solution provided by #856 (comment) works but don't really want to replace all my Thanks in advance |
@MikeYermolayev Supplying your custom implementation to |
Replacing
|
Since userEvent v14, this behaves a bit differently, and luckily seems to have a more simple solution. const user = userEvent.setup({ skipHover: true })
const user.click(myDropdownItemElement) |
Bug report
Current Behavior
When I want to open the menu via test (jest, react testing library) I cannot, radix looks amazing to me but before I refacttor my menus to use it I need it to be testable :)
Expected behavior
it should behave on jsdom the same as on the browser
Reproducible example
https://codesandbox.io/s/radix-dropdown-tests-forked-829re
Suggested solution
Tried looking at the code and wrote this test, the problem is that onPointerDown expects button: 0 and ctrlKey=false properites on the event, which apparently does not exist on jsdom.
Additional context
Upgraded rtl to latest version but its not enough apparently
I will dig more into this but I wondered if you had any thoughts on this, I saw there are no tests for dropdown-menu in the package.
Thanks!
Your environment
The text was updated successfully, but these errors were encountered: