question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

userEvent.type not working with <input type="time">

See original GitHub issue
  • @testing-library/user-event version: 12.2.0
  • Testing Framework and version: jest:26.6.0
  • DOM Environment: @testing-library/jest-dom:5.11.5

Relevant code or config

import React from 'react'
import { render, fireEvent } from '@testing-library/react'
import userEvent from '@testing-library/user-event'

function InputNumber() {
  return <input type="time" role="textbox" />
}

describe('Test <InputNumber>', () => {
  it('Update with fireEvent', () => {
    const { getByRole } = render(<InputNumber />)
    const input = getByRole('textbox')
    fireEvent.change(input, { target: { value: '01:01' } })
    expect(input.value).toBe('01:01')
  })

  it('Update with userEvent', () => {
    const { getByRole } = render(<InputNumber />)
    const input = getByRole('textbox')
    userEvent.type(input, '0101AM')
    expect(input.value).toBe('01:01') // <- FAILS
  })
})

What you did: Called userEvent.type on <input type="time">.

What happened: input.value remains "".

Problem description: It would seem that keystrokes are not making their way to the input field. I’ve tested this under both en-US and en-GB locales, the result is the same.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
kellengreencommented, Dec 4, 2020

Amazing work. Thank you.

1reaction
kentcdoddscommented, Nov 8, 2020

@gndelia, go for it 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

userEvent.type not updating value of input in test
If you update jest to the latest version it will work. Currently, the latest jest is 26.6.3.
Read more >
user-event v13 - Testing Library
import userEvent from '@testing-library/user-event' test('types into the input', () => { render( <> <label for="time">Enter a time</label>
Read more >
Simplify your tests with testing-library-selector
At first glance, this solution works very well! The problem is when you have to use different types of queries for the same...
Read more >
Mimicking User Interactions - Learn React Testing
Note: There is a known issue with the userEvent.type() method that was resolved in issue 12.0.4. To avoid this issue, install version 12.0.4...
Read more >
userEvent.type not updating value of input in test-Reactjs
') }) Callback in test() needs to be declared as async then, of course. Link to this in the docs at time of ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found