Skip to content

userEvent.pointer does not set the button and buttons properties #926

Closed
@alkstal

Description

@alkstal

Reproduction example

https://codesandbox.io/s/misty-haze-n45bf4?file=/src/App.js

Prerequisites

  1. <button>Touch me</button>
document.querySelector('button').addEventListener('pointerup', (e) => {
    console.log(e.button)
})
await user.pointer({
    tags: '[MouseLeft]',
    target: document.querySelector('button'),
})

Expected behavior

PointerEvent sets event.button and event.buttons to allow us to figure out which button was used.

https://developer.mozilla.org/en-US/docs/Web/API/Pointer_events#determining_button_states

As an example, if the left mouse button was used, the pointerup event event.button is 0.

Actual behavior

The PointerEvent created by userEvent.pointer() does not assign event.button or event.buttons, so both are undefined in a event handler.

This means event handlers using these properties don't work under test.

User-event version

14.0.4

Environment

Testing Library framework:

JS framework:

Test environment:

DOM implementation:

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions