user-event: Pointer Events check sometimes returns false positives

Reproduction example

https://codesandbox.io/s/exciting-fire-b1ibfk?file=/src/App.test.js

Prerequisites

If you run a userEvent.click on an element which then has pointer-events: none added after the interaction, then the next userEvent.clickon a different element thinks the element inherits pointer-events: none

Expected behavior

userEvent.click should not throw a warning.

Actual behavior

Error thrown “Unable to perform pointer interaction as the element has or inherits pointer-events set to “none”.”

User-event version

14.0.4

Environment

See sandbox, which is using React 18. I also see the issue in React 17 locally.

Additional context

No response

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 13
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I still have the issue in 14.4.3

For other users hitting this issue, I’ve worked around it by updating my config to ignore the hover events

const user = userEvent.setup({ skipHover: true });

@EEBK99 i don’t remember where i wrote that code, but it looks something like this

const element = getByRole('button', {name: "test"})

Instead of await userEvent.click(element)

I used element.click()

Thanks for the report. ❤️

Looks like this is not a false-positive for the other element. The implicit movement of the cursor out of the previously hovered element (that now has pointer-events: none) triggers the error. Replacing the user.click with userEvent.click, i.e. starting a new “session”, works, because it considers the pointer to be at document.body.

I think first of all we should improve the error message and report the target element as well as the element which has pointer-events: none.

Then we should probably not throw an error but just skip the events if the target was not explicitly mentioned in the API call, i.e. click(elX) should only throw if elX receives no pointer events. Removing the check for previous position might be a mistake though, because unhover(elX) should probably still throw.

I also have this issue in 14.5.1. Unfortunately I do not have capacity to add a repro right now.

🎉 This issue has been resolved in version 14.2.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

We still experience this issue even with the pointerEventsCheck: PointerEventsCheckLevel.EachTrigger in place!