testing-library / testing-library/dom-testing-library

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

Open
#1,339 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
3.3k
Forks
474
PR merge metrics
No merged PRs in 30d

Description

  • @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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the fireEvent.click path for click, auxclick, and contextmenu events, using the reported Jest coverage gap as a guide. Check how the supplied pointerId and pointerType properties are handled, then run the relevant Jest tests and confirm those properties are preserved for all three event types.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
testing-qa
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.