Skip to content

fix: default pointer event pointerType to empty string instead of the string "undefined" - #1325

Merged
snowystinger merged 5 commits into
testing-library:mainfrom
tzh476:fix/click-pointertype-undefined
Aug 22, 2026
Merged

fix: default pointer event pointerType to empty string instead of the string "undefined"#1325
snowystinger merged 5 commits into
testing-library:mainfrom
tzh476:fix/click-pointertype-undefined

Conversation

@tzh476

@tzh476 tzh476 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What

Set pointerType to an empty string on synthetic click events when no pointer type was provided, instead of setting it to the string "undefined".

Why

initPointerEvent used String(pointerType). When pointerType is missing, that becomes the invalid token "undefined". Real click events can have an unset pointerType; they should never use that string.

Fixes #1291

How

Set pointerType to an empty string when it is defined.

Testing

  • Added unit tests for a keyboard click as well as for the constructor

Checklist

  • Tests
  • Ready to be merged

Made with Cursor

String(undefined) produced an invalid pointerType token. Pointer events
without an explicit type should leave the property unset.

Change-Id: Ib2f744ee8eb282499c83e5f483d9301d4b3d5e99
Co-authored-by: Cursor <cursoragent@cursor.com>
@snowystinger

Copy link
Copy Markdown
Contributor

Thanks for the PR. I don't think this is quite right, you're editing the initialisation of the PointerEvent, but the spec says that it should be initialised to an empty string https://w3c.github.io/pointerevents/#pointerevent-interface so it shouldn't ever be undefined.

I checked this on Chrome as well, https://jsfiddle.net/f6nLaruj/ by focusing the button, then pressing "Enter". This results in click followed by an empty string ''.

It'd be good to test the same user flow instead of directly asserting on createEvent, that's not a very helpful test as it's not something we can compare the results of against browsers. It's useful to stop a regression, but for proof for this PR, it's not accurate.

Change-Id: I1754ed6e71ea154f86d8e4ea75c5729f32c63b62
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@tzh476

tzh476 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor Author

Updated in 32e4155:

  • Initialized pointerType to '' (empty string) when not provided/undefined, conforming to the W3C PointerEventInit specification default.
  • Added tests asserting pointerType: '' on default event initialization and on keyboard-triggered click events ([Enter] on button elements).

Comment thread src/event/createEvent.ts Outdated
Co-authored-by: Rob Snow <snowystinger@gmail.com>
Comment thread src/event/createEvent.ts Outdated
reduce whitespace changes

Co-authored-by: Rob Snow <snowystinger@gmail.com>
@snowystinger snowystinger changed the title fix: keep click pointerType undefined instead of the string "undefined" fix: default pointer event pointerType to empty string instead of the string "undefined" Aug 22, 2026
@snowystinger
snowystinger merged commit 71a5475 into testing-library:main Aug 22, 2026
2 checks passed
@github-actions

Copy link
Copy Markdown

馃帀 This PR is included in version 14.6.6 馃帀

The release is available on:

Your semantic-release bot 馃摝馃殌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

click event has wrong pointerType of the string "undefined"

2 participants