-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
userEvent.type(input, 'text') consistently shuffles the input #391
Comments
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: user-event/src/__tests__/type.js Lines 109 to 144 in 26d2462
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. |
I just noticed this:
Might this be related? |
I can take a look at this later. |
This bug was introduced in #322 (version 11.3.1) |
this issue is like #346. The problem is that when the We can add a check at the beginning of diff --git a/src/type.js b/src/type.js
index 0bee11e..632dc97 100644
--- a/src/type.js
+++ b/src/type.js
@@ -65,6 +65,15 @@ async function typeImpl(
}
return value
}
+
+ if (
+ typeof currentElement().selectionStart === 'undefined' ||
+ typeof currentElement().selectionEnd === 'undefined'
+ ) {
+ currentElement().setSelectionRange(0, 0)
+ }
+
const setSelectionRange = ({newValue, newSelectionStart}) => {
// if we *can* change the selection start, then we will if the new value
// is the same as the current value (so it wasn't programatically changed |
Is there any way we can alter the code in other places so we don't actually set the selection range? |
This comment has been minimized.
This comment has been minimized.
This issue and #346 have been fixed in JSDOM, but Code Sandbox's Jest support is still hard coded to use JSDOM 4.0.0, which doesn't have the fix: https://github.com/codesandbox/codesandbox-client/pull/1812/files#diff-3fcdeb2de813a974b29d8610b234c7f2R51 There are two ways to solve this:
If anyone's curious, I've reproduced this issue using jest Code Sandbox, without any React or Testing Library packages: https://codesandbox.io/s/code-sandbox-bug-with-old-jsdom-version-9gcnp?file=/index.test.js |
I think codesandbox will be making an effort to address some of these issues soon. |
Do we want to close this to track it upstream instead of patching |
Yeah, I don't want to worry about supporting old versions of JSDOM |
The issue has been resolved on |
I can get this issue resolved on the codesandbox, but when i download the project from codesandbox and run locally, i still get this issue. Is this still expected? Thanks in advance. |
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 |
Hey guys, just stumbled on this. Is there a solution for this, or do I just need to install and set |
You can check your jsdom version with |
Thanks @nickmccurdy, it solved this issue. Currently having the issue of #387, but that's another problem... |
@testing-library/user-event
version: 12.0.11jest-environment-jsdom-fourteen
)I'm having some issues with the following test-snippet (copied from the readme with some minor modification):
When I run this, it fails with the following output:
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.The text was updated successfully, but these errors were encountered: