Description
Reproduction example
Unit test case in issue
Prerequisites
import { createEvent } from '#src/event/createEvent'
import { render } from '#testHelpers'
test('it does not stringify click pointerType', () => {
const { element } = render(`<input type="checkbox"/>`)
const event = createEvent('click', element)
expect(event).toHaveProperty('pointerType', undefined)
})
Expected behavior
Test passes
Actual behavior
FAIL tests/event/createEvent.ts
● it does not stringify click pointerType
expect(received).toHaveProperty(path, value)
Expected path: "pointerType"
Expected value: undefined
Received value: "undefined"
5 | const { element } = render(`<input type="checkbox"/>`)
6 | const event = createEvent('click', element)
> 7 | expect(event).toHaveProperty('pointerType', undefined)
| ^
8 | })
9 |
at Object.toHaveProperty (tests/event/createEvent.ts:7:19)
User-event version
14.6.1
Environment
Testing Library framework: @testing-library/react@13.4.0
JS framework: react@18.2.0
Test environment: jest@29.5.0
DOM implementation: jsdom@26.1.0
Additional context
Simulating a click
does produce an event with an invalid pointerType
of "undefined"
(as string).
It is expected that pointerType
can be undefined
, but it should never be that string.
The cause for this is this line of code:
user-event/src/event/createEvent.ts
Line 271 in 63ac399
I tried adding a simple PR that accounts for undefined
here, but due to the nature of assignProps
, the undefined
value will be turned into null
, which is also not correct:
user-event/src/event/createEvent.ts
Lines 101 to 105 in 63ac399
Updating assignProps
lead to too many snapshot changes, so I didn't pursue this further, but hope I've provided enough information that allows provide a fix.
Thanks 🙌