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(input, 'text') consistently shuffles the input

See original GitHub issue
  • @testing-library/user-event version: 12.0.11
  • Testing Framework and version: jest@24.9.0
  • DOM Environment: jsdom@14.0.0 (via jest-environment-jsdom-fourteen)

I’m having some issues with the following test-snippet (copied from the readme with some minor modification):

test('type', () => {
  render(<textarea />);

  userEvent.type(screen.getByRole('textbox'), 'hey');
  expect(screen.getByRole('textbox')).toHaveValue('hey');
});

When I run this, it fails with the following output:

image

Whatever text i input, it chucks the first input-character at the end, (i.e. 123 -> 231).

I’m guessing this is not the expected outcome - or if so, what am I missing? 😁

I’m using fireEvent.change(screen.getByRole('textbox'), { target: { value: 'hey' } }) as a workaround for now.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:11
  • Comments:18 (13 by maintainers)

github_iconTop GitHub Comments

9reactions
nickmccurdycommented, Aug 21, 2020

Code Sandbox has now pinned JSDOM 16, but create-react-app (which is used when downloading the sandbox) is still stuck on JSDOM 14. You can work around this by installing jest-environment-jsdom-sixteen and adding --env jest-environment-jsdom-sixteen to the test script until CRA is updated with Jest 26 support.

4reactions
kentcdoddscommented, Jun 26, 2020

I have reproduced this issue: https://codesandbox.io/s/pedantic-maxwell-wu50t?file=/src/__tests__/index.js

I’m guessing it’s something odd with React because we absolutely have tests for this:

https://github.com/testing-library/user-event/blob/26d246269058228a8255aa1ce8b3e438aa7ad3e2/src/__tests__/type.js#L109-L144

I’m not sure what the problem is, but if someone wants to investigate and figure out what we’re doing wrong that would be great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

user-event v13 - Testing Library
You should use userEvent.type if you just want to conveniently insert some text into an input field or textarea.
Read more >
userEvent.type shuffles the letters for textarea - Stack Overflow
So the letters are shuffled with no apparent reason (the first and the last letter). It works fine for the input but for...
Read more >
React-testing-library: fireEvent vs userEvent - mimacom blog
As we can see, we're only creating a button and a text input with some event handlers associated to them, and we've added...
Read more >
SuiteScript 2.x Map/Reduce Script Type - Oracle Help Center
The map/reduce script type is designed for scripts that need to handle large ... this output data is sent as input to the...
Read more >
BrightAuthor User Guide (ver 4.6).pdf - KVMGalore
You can create three types of presentation in BrightAuthor: ... Interactive: A presentation that transitions between media based on input from a user...
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