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 only types last character or gives act warning when using Formik #539
Comments
You could not reproduce the error in codesandbox because your codesandbox example does not contain the failing test.;) This looks like an issue with Formik because this test does pass: test("Delayed change to unexpected value", () => {
render(<App />);
const firstNameInput = screen.getByTestId("firstName");
userEvent.type(firstNameInput, "MyFirstName");
expect(firstNameInput.value).toBe("MyFirstName");
waitFor(() => expect(firstNameInput.value).toBe("e"));
}); |
What makes think you this is a Formik issue? I see the test passing without act warnings, it's quite strange. I'm not sure how to pinpoint whether this is a userEvent issue or Formik issue. We could throw this back and forth forever, and it seems like a pretty basic issue. |
Sry, stupid mistake on my part - didn't await/return the Promise. The test does fail when written correctly: return waitFor(() => expect(firstNameInput.value).toBe("e")); This is the fix for your test: test("fixed", async () => {
render(<App />);
const firstNameInput = screen.getByTestId("firstName");
await userEvent.type(firstNameInput, "MyFirstName", { delay: 1 });
expect(firstNameInput.value).toBe("MyFirstName");
}); Formik applies the state change asynchronously. That's why they happen out of the |
Seems like a bit of a hacky and non-obvious solution, but I'm glad I can move on at least. Do you still believe this is a Formik issue and not a userEvent issue? |
I thought so because when trying to reproduce the described behavior the test above succeeded although it should fail. And it does fail (without the slip of the pen)... If there is a Formik issue or if this is the expected Formik behavior, I don't know. The whole idea to simulate browser behavior without using a browser is hacky... |
I needed to do await userEvent.type vs just userEvent.type and the delay. |
FYI |
Either
The issue has been mentioned here, but it seems to have been closed?
I'm able to reproduce the error after creating a new CRA project yesterday, but not on CodeSandbox?
App.js
App.test.js
What you did:
Created a new project using npx create-react-app, added formik
What happened:
Reproduction repository:
https://github.com/Hyllesen/testing-library-formik-bug
I could not reproduce the error in codesandbox, https://codesandbox.io/s/youthful-river-0wxrz
@testing-library/user-event: v12.6.0
@testing-library/jest-dom: ^5.11.4
@testing-library/react: ^11.1.0
@testing-library/user-event: 12.6.0
formik": "^2.2.6
node@v14.15.1
The text was updated successfully, but these errors were encountered: