Skip to content
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

[DropdownMenu] Not opening after being clicked on tests #1207

Closed
rubenmoya opened this issue Feb 28, 2022 · 1 comment
Closed

[DropdownMenu] Not opening after being clicked on tests #1207

rubenmoya opened this issue Feb 28, 2022 · 1 comment

Comments

@rubenmoya
Copy link

Bug report

Current Behavior

When testing a component using the DropdownMenu and userEvent.click the dropdown does not open. It does open on the browser, it just fails on the tests.

Expected behavior

The dropdown opens and the items can be selected.

Reproducible example

Github repo using CRA

Additional context

We were trying to update a project from 0.0.22 to the latest version. After downgrading I discovered it started failing since 0.0.23.

Your environment

Software Name(s) Version
Radix Package(s) @radix-ui/react-dropdown-menu 0.0.23 to latest
React n/a ^17.0.2
Browser Chrome
Assistive tech
Node n/a v16.13.0
npm/yarn yarn 1.22.17
Operating System Kubuntu
@andy-hook
Copy link
Contributor

andy-hook commented Feb 28, 2022

This is an issue with how JSDom emulates pointerEvent, it doesn't currently provide the correct event object properties. You'll need to supply these manually or use an alternative testing tool such as Cypress.

See this comment for a working solution #856 (comment)

// test/helpers.ts
export class PointerEvent extends Event {
  button: number;
  ctrlKey: boolean;

  constructor(type, props) {
    super(type, props);
    if (props.button != null) {
      this.button = props.button;
    }
    if (props.ctrlKey != null) {
      this.ctrlKey = props.ctrlKey;
    }
  }
}

// dropdownMenu.test.tsx
fireEvent.pointerDown(
  button,
  new PointerEvent('pointerdown', {
    ctrlKey: false,
    button: 0,
  })
);

0.0.23 and upwards started using pointerEvent which is why you're seeing this now.

I'm going to close this issue but if you're still having problems or have other questions then feel free to re-open and we'll do our best to help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants