Skip to content

type causes InvalidStateError with <input type="email"> #316

@kelvinlzhang

Description

@kelvinlzhang

Occurs in master of @testing-library/user-event version: 11.2.1

Here's an example failing test, not really up to this library's standards but I wanted to get as close to the source as possible.

STR:

  1. Add the following block to src/__tests__/type.js
const create = () => {
    const utils = render(<input aria-label="input" type="email"/>)
    const input = utils.getByLabelText('input')
    return {
        input,
        ...utils,
    }
}

it('types text in email input', async () => {
    const { input } = create()
    await userEvent.type(input, '[email protected]')
    expect(input.value).toBe('[email protected]')
})
  1. Run test
  2. InvalidStateError

What happened: I wanted to follow up on this comment and reproduce: #307 (comment). Sorry @kentcdodds, the type= was abstracted away and it was pretty silly of me to assume it was text. Seems like I ran into 2 completely different issues now, but hopefully I'm just missing something obvious.

Test fails on InvalidStateError, adding an onChange handler with a console.log(event.target.value) shows that type only enters in the first char before breaking.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions