Skip to content

click event has wrong pointerType of the string "undefined" #1291

Open
@stigi

Description

@stigi

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:

pointerType: String(pointerType),

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:

function assignProps<T extends object>(obj: T, props: {[k in keyof T]?: T[k]}) {
for (const [key, value] of Object.entries(props)) {
Object.defineProperty(obj, key, {get: () => value ?? null})
}
}

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 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds assessmentThis needs to be looked at by a team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions