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

Handle maxLength for userEvent.type #185

Merged

Conversation

klujanrosas
Copy link
Contributor

@klujanrosas klujanrosas commented Nov 19, 2019

This is related to #161 .
I took the liberty to implement it. I look forward to your comments or suggestions.

@codecov
Copy link

codecov bot commented Nov 19, 2019

Codecov Report

Merging #185 into master will increase coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #185      +/-   ##
==========================================
+ Coverage    97.2%   97.24%   +0.03%     
==========================================
  Files           1        1              
  Lines         143      145       +2     
  Branches       34       35       +1     
==========================================
+ Hits          139      141       +2     
  Misses          4        4
Impacted Files Coverage Δ
src/index.js 97.24% <100%> (+0.03%) ⬆️

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 0ad9eed...0dcd8c1. Read the comment docs.

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

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

LGTM! Should we also check if tests are passing when allAtOnce is false? Can't think of a reason why this would make it fail, but I'd also love to make sure it doesn't since we modified both if branches from opts.allAtOnce.

@klujanrosas
Copy link
Contributor Author

@afontcu I also can't think of a reason why they would fail, but one can never be too cautious!

I will find some time to add those tests as well, thank you

@klujanrosas
Copy link
Contributor Author

@afontcu sorry to bother you, could this be reviewed again?

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

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

LGTM! I'll let @Gpx review and merge it :)

@kentcdodds
Copy link
Member

Are we sure the browser doesn't continue to fire input events even though the maxlength is reached? We don't have to actually update the value, but we should make sure we fire all the same events the browser does.

@calebeby
Copy link
Contributor

@kentcdodds I just tested an input with a maxlength, it looks like it only fires input events till the max length is reached.

@kentcdodds
Copy link
Member

Cool. Are we still firing keyup/keydown events?

@calebeby
Copy link
Contributor

I'm pretty sure that we should be, but I'm not sure whether it does in this PR

@klujanrosas
Copy link
Contributor Author

@kentcdodds @calebeby that makes sense, I will update this PR so it still fires keyup/keydown events, thank you for your comments

@carlos-cne
Copy link

Hi! I arrived here because I have an input with a max-length attribute.
When I call userEvent.type(...) with a string more than max-length, it does not work and I got a string with more than max-length.

I'm testing if input.value is equal to max-length
expect(inputValue.value).toHaveLength(60);

@kentcdodds
Copy link
Member

Hi @carlos-cne,

Yes, once this PR is updated and then merged that issue should go away.

@klujanrosas klujanrosas force-pushed the feature/handle-input-max-length branch from 0aa8a64 to cb0f5e9 Compare January 29, 2020 20:06
@klujanrosas
Copy link
Contributor Author

@Gpx @kentcdodds I've updated this to reflect what was suggested in the comments above, let me know if there's anything else that I should cover or change 🐣

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.

Looks good to me! Thank you so much :)

Comment on lines +187 to +189
expect(keydown).not.toHaveBeenCalled();
expect(keypress).not.toHaveBeenCalled();
expect(keyup).not.toHaveBeenCalled();
Copy link
Member

Choose a reason for hiding this comment

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

Wait, shouldn't these all be called several times?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not for allAtOnce: true afaik

Copy link
Member

Choose a reason for hiding this comment

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

Oh

Oh! lol, my bad.

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.

Super 👍

@kentcdodds kentcdodds merged commit 259fb3a into testing-library:master Jan 29, 2020
@kentcdodds
Copy link
Member

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

@allcontributors
Copy link
Contributor

@kentcdodds

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

@Gpx
Copy link
Member

Gpx commented Jan 29, 2020

🎉 This PR is included in version 8.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Gpx Gpx added the released label Jan 29, 2020
@klujanrosas klujanrosas deleted the feature/handle-input-max-length branch January 31, 2020 01:53
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

6 participants