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.

`.type` dont work with `datetime-local` inputs

See original GitHub issue
  • @testing-library/user-event version: 13.1.9
  • Testing Framework and version: jest 27.0.5
  • DOM Environment: jsdom (default jest version)

Relevant code or config

import '@testing-library/jest-dom/extend-expect'
import {render, screen} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import React from 'react'

const Input = () => {
  return <input type="datetime-local" data-testid="input" />
}

test('works properly', () => {
  render(<Input />)

  const value = '2000-01-01T00:00'
  const elInput = screen.getByTestId('input')

  expect(elInput).toBeVisible()
  expect(elInput).toBeEnabled()
  expect(elInput).toHaveValue('')

  userEvent.type(elInput, value)

  expect(elInput).toHaveValue(value)
})

What you did: tried to type a date to the datetime input

What happened: no date has been entered on the input

Reproduction repository: https://codesandbox.io/s/gifted-kapitsa-dfhst?file=/main.test.js

Problem description:

Suggested solution: I’ve seen previous similar issues (for date or time inputs), and I think it’s just a matter to include a branch logic for datetime-local inputs.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:3
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ph-fritschecommented, May 12, 2022

@Fox32 With consistent behavior across browsers we might consider an implementation. An issue collecting information on the browser behavior and discussing possible implementations would be welcome. The UI representation as used by the browser is not programmatically available. So an implementation would need to fill the gap between the (perceived) user interaction and the IDL properties.

1reaction
Fox32commented, Apr 25, 2022

Looks like Firefox has support nowadays (https://bugzilla.mozilla.org/show_bug.cgi?id=1283388) and behaves similar to Chrome. Can we have another look at this issue?

Read more comments on GitHub >

github_iconTop Results From Across the Web

<input type="datetime-local"> - HTML - MDN Web Docs
A string representing the value of the date entered into the input. The format of the date and time value used by this...
Read more >
html - Input type DateTime - Value format? - Stack Overflow
<input type="datetime-local" name="dtl" step="7200"> Because datetime steps through one minute at a time, you may want to change the default increment by using ......
Read more >
Using the input datetime-local - Andrea Giammarchi
As you probably know already, in order to avoid awkward and confusing user experience due time zones, the input type datetime has been...
Read more >
Blazor input type datetime-local doesn't trigger @onchange in ...
If an input of the type "datetime-local" is used, the @onchange event is not triggered under Firefox. Firefox' console shows Uncaught Error: ...
Read more >
HTML input type="datetime-local" - W3Schools
The <input type="datetime-local"> defines a date picker. The resulting value includes the year, month, day, and time. Tip: Always add the <label> tag...
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