jestjsreact-testing-libraryuser-event

How can I use number Value in react-testing-library userEvent


Recently, I am changing fireEvent to userEvent. If the type value of userEvent is number, a type error occurs, but is it not possible to use the number type for the value in userEvent?

  await userEvent.type(
    screen.getByRole('textbox', { name: 'pay' }),
   1000 //type error
  );

Solution

  • userEvent.type expects a string because that's how it represents sequences of keys being pressed. You can fix this specific example by changing 1000 to '1000'. If you need to do this dynamically, you can use .toString() instead.