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() breaks with a number

See original GitHub issue

Not sure if this is a bug, or as intended, so feel free to close 😃

I I just tried to do this:

await userEvent.type(screen.getByPlaceholderText('Price'), item.price);

Where price is a number. That throws the error TypeError: text.slice is not a function

running with toString() fixes that:

await userEvent.type(screen.getByPlaceholderText('Price'), item.price.toString());

Since the browser would coerce to a string if we were setting a value, should this too? Or should I just always coerce it myself?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
gap777commented, Mar 3, 2021

We’re seeing a situation where type with a string on a number input doesn’t work… the browser wants a number to be entered, not a string. Any way to do this?

1reaction
wesboscommented, Feb 17, 2020

Makes sense! Thanks a lot

Read more comments on GitHub >

github_iconTop Results From Across the Web

user-event v13 - Testing Library
Simulates the keyboard events described by text . This is similar to userEvent.type() but without any clicking or changing the selection range.
Read more >
How to use user-event library in conjunction with Jest's fake ...
I'm writing Jest tests for a React component, and using the @testing-library/user-event library to simulate user interaction. This works great, ...
Read more >
React Testing Library best practices | Ben Ilegbodu
The type user event writes the specified text into the <textarea> ... {enter} (hitting the ENTER key) instead of a line break (...
Read more >
React Testing Techniques - Medium
A refactor can easily break your test. Another example is using certain APIs of a React testing tool called Enzyme, e.g. its instance()...
Read more >
Common mistakes with React Testing Library - Kent C. Dodds
You only need to type screen. and let your editor's magic autocomplete take ... toBeDisabled() // error message: // Received element is not ......
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