Why is React-Testing-Library / Jest receiving DOM input backwards?

Viewed 1141

When testing a form, I am using userEvent to type 'hello' into a textbox, then when testing the value of said textbox straight after, using toHaveValue(), it returns the string backwards...

 render(<Form />)
 userEvent.clear(screen.getAllByRole('textbox')[0])
 userEvent.type(screen.getAllByRole('textbox')[0], 'hello')
 expect(screen.getAllByRole('textbox')[0]).toHaveValue('hello')

The error in console after running yarn test: enter image description here

Package versions:

    "react-scripts": "^3.4.3",
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^12.0.0",
    "@testing-library/user-event": "^13.1.9",
1 Answers

I experienced the same thing, and I was previously on jest ^24.8.0, and after upgrading to the latest (jest ^27.2.1) the issue was resolved.

Related