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

click, auxclick and contextmenu events don't support PointerEvent properties #1339

Open
JoshTumath opened this issue Nov 15, 2024 · 1 comment

Comments

@JoshTumath
Copy link

  • @testing-library/dom version: 9.3.4
  • Testing Framework and version: Jest 29.7.0
  • DOM Environment: jsdom 24.0.0

Relevant code or config:

To simulate a pointer click, I might want to provide properties from the PointerEvent interface, such as:

// When simulating a mouse pointer input
fireEvent.click(button, {
  pointerId: 123,
  pointerType: 'mouse'
});

// When simulating a keyboard input
fireEvent.click(button, {
  pointerId: -1,
  pointerType: ''
});

What you did:

I tried to simulate a pointerId property in a click event.

What happened:

The Jest code coverage reported that the if statement in my event handler

Reproduction:

I haven't done one in case the problem is obvious, but I am happy to create one if asked.

Problem description:

All browsers now treat a click event as a type of PointerEvent, not a MouseEvent. However, the @testing-library still treats them as MouseEvent types, so when I want to use properties like pointerId in tests, they get ignored.

Suggested solution:

Change auxclick, click and contextmenu events to PointerEvent types.

@MatanBobi
Copy link
Member

Thanks for opening this @JoshTumath.
fireEvent is a lower level API and should be used sparingly. AFAIR, user-event uses PointerEvents for clicks. Have you tried that?

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