You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compare to the console when running the test with user.click
Expected behavior
Both should fire
pointerDown
pointerUp
click
Actual behavior
The test does not fire click
I'll provide more in additional context because the codesandbox behaves a little differently than when I run this repos tests with two tests I think cover the behavior
I think these are the behaviors that would be expected, assuming I wrote them correctly.
In english:
calling user.click with preventDefault on pointerDown should result in pointerDown, pointerUp, and click being fired
calling user.pointer with preventDefault on pointerDown should also result in pointerDown, pointerUp, and click being fired
test('preventDefault on pointer down prevents compatibility events works with click', async () => {
const {element, getClickEventsSnapshot, getEvents, user} = setup('<div />', {eventHandlers: {pointerdown: e => e.preventDefault()}})
await user.click(element)
expect(getClickEventsSnapshot()).toMatchInlineSnapshot(`
pointerdown - pointerId=1; pointerType=mouse; isPrimary=true
pointerup - pointerId=1; pointerType=mouse; isPrimary=true
click - button=0; buttons=0; detail=1
`)
expect(getEvents('click')).toHaveLength(1)
})
test('preventDefault on pointer down prevents compatibility events works with pointer', async () => {
const {element, getClickEventsSnapshot, getEvents, user} = setup('<div />', {eventHandlers: {pointerdown: e => e.preventDefault()}})
await user.pointer({keys: '[MouseLeft]', target: element})
expect(getClickEventsSnapshot()).toMatchInlineSnapshot(`
pointerdown - pointerId=1; pointerType=mouse; isPrimary=true
pointerup - pointerId=1; pointerType=mouse; isPrimary=true
click - button=0; buttons=0; detail=1
`)
expect(getEvents('click')).toHaveLength(1)
})
snowystinger
changed the title
Click compatibility events cannot be prevented
Click and DoubleClick not fired if pointerDown has preventDefault
Apr 25, 2023
I just ran into this bug as well - any way we can get a review of @snowystinger 's PR prioritized sometime soon? Looks like the PR and this issue's been open for a bit without eyes on it 😞
Reproduction example
https://codesandbox.io/s/aged-voice-xjf3dw
Prerequisites
Expected behavior
Both should fire
Actual behavior
The test does not fire click
I'll provide more in additional context because the codesandbox behaves a little differently than when I run this repos tests with two tests I think cover the behavior
User-event version
14.4.3
Environment
Testing Library framework:
@testing-library/react@13.4.0
JS framework:
react@18.2.0
Test environment:
jest@28.1.3
DOM implementation:
jsdom@20.0.3
Additional context
I think these are the behaviors that would be expected, assuming I wrote them correctly.
In english:
calling user.click with preventDefault on pointerDown should result in pointerDown, pointerUp, and click being fired
calling user.pointer with preventDefault on pointerDown should also result in pointerDown, pointerUp, and click being fired
I think this is handled here https://github.com/testing-library/user-event/blob/main/src/system/pointer/index.ts#L105 but I've checked and isPrevented is true. So I'm not sure why the mouse events are getting fired.
It looks like including a 'click' is part of system/pointer/mouse. So guessing that would need to be pulled up and out of there.
The text was updated successfully, but these errors were encountered: