user-event
user-event copied to clipboard
Typing Backspace multiple times results in wrong cursor position
Reproduction example
https://codesandbox.io/s/elastic-surf-6qegdh?file=/src/App.test.js
Prerequisites
- Render
<input type="text" /> - Type
abc - Press
{ArrowLeft}{Backspace}{Backspace}
Expected behavior
input element value should be 'c' and cursor position should be 0
Actual behavior
The input element value is "a" and the cursor position is 1
User-event version
14.4.3
Environment
Testing Library framework:
JS framework:
Test environment:
DOM implementation:
Additional context
No response
I experience similar problem and it boiled down to incorrect behavior with React 17 starting v14.2.6.
Test:
- Render
<input type="text" />and focus it. - Using only
keyboardpressa,b,e,h - Press
{ArrowLeft},{ArrowLeft} - Press
C,D - Press
{ArrowRight} - Press
F,G
Expected input value: abCDeFGh
Received input value: abCehDFG
Codepens:
- React 17, user-event 14.2.5, @testing-library/react 12.1.5 — no issue
- React 17, user-event 14.2.6, @testing-library/react 12.1.5 — issue is present, including v14.4.3
- React 18, user-event 14.4.3, @testing-library/react 13.4.0 — no issue
Most likely this PR caused regression for React 17 in v14.2.6.