Skip to content
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

fix: add message if type/paste function is called with an invalid element #375

Conversation

marcosvega91
Copy link
Member

@marcosvega91 marcosvega91 commented Jun 21, 2020

What:

I have thrown a new TypeError if the user calls userEvent.type or userEvent.paste with an element that has no value.
This PR is part of issue #356.

Why:

Because as it was before the PR the error was not very helpful

image

How:

By checking if the currentElement has value property.
The message thrown is like this the current element is of type BODY and doesn't have a valid value

Checklist:

  • Documentation
  • Tests
  • Typings
  • Ready to be merged

If the user tries to call type function with an invalid element, an explicit error will be thrown.
This error should be better then 'TypeError: Cannot read property 'length' of undefined'
@marcosvega91 marcosvega91 changed the title Pr/add message invalid type element fix: add message if type function is called with an invalid element Jun 21, 2020
@codecov
Copy link

codecov bot commented Jun 21, 2020

Codecov Report

Merging #375 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #375   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           12        12           
  Lines          385       392    +7     
  Branches       111       113    +2     
=========================================
+ Hits           385       392    +7     
Impacted Files Coverage Δ
src/utils.js 100.00% <ø> (ø)
src/paste.js 100.00% <100.00%> (ø)
src/type.js 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2e55359...a3e3249. Read the comment docs.

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also do this check in the currentValue function in type.

@marcosvega91
Copy link
Member Author

I'm looking the code better and maybe there could be other problems like this

user-event/src/type.js

Lines 253 to 254 in 50e330b

function calculateNewBackspaceValue(element) {
const {selectionStart, selectionEnd, value} = element

user-event/src/type.js

Lines 286 to 287 in 50e330b

function calculateNewDeleteValue(element) {
const {selectionStart, selectionEnd, value} = element

Maybe we should use currentValue also in the other parts?

@kentcdodds
Copy link
Member

Whatever you think makes the most sense 👍

@marcosvega91 marcosvega91 changed the title fix: add message if type function is called with an invalid element fix: add message if type/paste function is called with an invalid element Jun 21, 2020
@marcosvega91
Copy link
Member Author

I have made the changes. I have updated also paste function with this logic

Copy link
Member

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great. Thanks!

@kentcdodds kentcdodds merged commit 0dd387e into testing-library:master Jun 21, 2020
@kentcdodds
Copy link
Member

@all-contributors please add @marcosvega91 for code and tests

@allcontributors
Copy link
Contributor

@kentcdodds

I've put up a pull request to add @marcosvega91! 🎉

@kentcdodds
Copy link
Member

Thanks so much for your help! I've added you as a collaborator on the project. Please make sure that you review the other/MAINTAINING.md and CONTRIBUTING.md files (specifically the bit about the commit messages and the git hooks) and familiarize yourself with the code of conduct (we're using the contributor covenant). You might also want to watch the repo to be notified when someone files an issue/PR. Please continue to make PRs as you feel the need (you can make your branches directly on the repo rather than your fork if you want). Thanks! And welcome to the team :)

@kentcdodds
Copy link
Member

🎉 This PR is included in version 12.0.6 🎉

The release is available on:

Your semantic-release bot 📦🚀

@marcosvega91
Copy link
Member Author

thank you @kentcdodds, it's awesome. I'm really happy to be part of another team of testing library 🥳 .
I like a lot the project and I hope to do always good thing 🦇

Thank you for all the things that you are doing for the community and the opportunity that you give to all of us ❤️

@marcosvega91 marcosvega91 deleted the pr/add_message_invalid_type_element branch June 22, 2020 05:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants