The type event doesn't work on elements without a value property
See original GitHub issue@testing-library/user-event
version: 12.1.10- Testing Framework and version: jest 24.1.0
- DOM Environment: react-dom 16.13.1
Relevant code or config
import React from 'react'
import '@testing-library/jest-dom'
import userEvent from '@testing-library/user-event'
import {render, screen} from '@testing-library/react'
import {useHotkeys} from 'react-hotkeys-hook'
function Counter() {
const [count, setCount] = React.useState(0)
useHotkeys('ctrl+k', () => setCount(prevCount => prevCount + 1))
return <>Pressed {count} times.</>
}
test('increment counter', async () => {
render(<Counter />)
const count = screen.getByText('Pressed 0 times.')
userEvent.type(document.body, '{ctrl}k{/ctrl}')
expect(count).toHaveTextContent('Pressed 1 times.')
})
Reproduction repository
https://codesandbox.io/s/blissful-waterfall-p4fi4?file=/src/index.test.js
Problem description
The library doesn’t seem to support the type
event on elements that don’t have a value
property. This prevents testing scenarios with global keyboard shortcuts that trigger effects. For instance, in the above sandbox, we increment the counter when hitting ctrl+k
(bound to document.body
) as you can see in the Browser tab (make sure the document is focused).
However, the test using userEvent.type
doesn’t pass (see Tests tab). It does with fireEvent.keyDown
.
Is it in the vision of user-event
to support this, or should it remain a fireEvent
scenario? And if the latter, what is the rationale?
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Property 'value' does not exist on type EventTarget in TypeScript
The $event is now a specific KeyboardEvent . Not all elements have a value property so it casts target to an input element....
Read more >How to fix property not existing on EventTarget in TypeScript
This error occurs when you try to access a property on an event target in TypeScript. Property 'value' does not exist on type...
Read more >Solved: TS "Property '…' does not exist on type 'EventTarget'"
Assuming that the event target is an HTML input element, we can fix this error like so: // Property 'form' does not exist...
Read more >Property 'value' does not exist on type 'EventTarget' Error in ...
This error is flagged by the TypeScript compiler. The $event in both examples are of type HTMLElement . It can represent any HTML...
Read more >Property 'value' does not exist on type 'EventTarget'. #6879
The error says event.target doesn't have a property named value , which is weird.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we should support
type
on non-value elements 👍I can’t remember 😅 so I guess we can just go forward.