-
Notifications
You must be signed in to change notification settings - Fork 219
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
Phone number does not validate in React Testing Library test #347
Comments
A little more info: when I try printing the values received by |
Hi @jamenamcinteer! Thanks for the thorough report! I'm digging into this a bit this weekend to see if I can get a grip on why it happens. If it's something you'd be interested in tackling, let me know! |
I dug into it a bit and was able to isolate the issue to an asynchronous import to the library that handles the "core" of phone number validation / manipulation. During initialization, it will use I'm going to look into making that dependency a synchronous import and cleaning it up, but this might require some time given that it involves some rewriting of another package and/or some research into an alternative. In the meantime, I've found that "shortcircuiting" the async import by importing it yourself in your test suite solves the issue. This is a crude workaround. You could also figure out an dirty You can add
Let me know if it solves the issue on your end, it seemed to work on mine. Anyhow, I'm starting work on addressing the root cause so that this workaround isn't needed longer than it needs to be. |
Hey @mcataford! Thank you so much for looking into this. I tried the workaround in my project and it works perfectly. I appreciate all your help with this! |
Glad it worked out! Since the root cause is documented in #348 and we've got a workaround for your use case, I'll go ahead and close this issue for now. Don't hesitate if you find out any more wonky interactions with RTL! |
Expected Behavior
If the phone number entered in the component is valid, the
isValid
property should betrue
when running React Testing Library tests (tests should match what is experienced in the browser).Current Behavior
In the browser, when a valid phone number is entered in the component (or passed in as the
defaultValue
), theisValid
property as seen withonPhoneNumberBlur
, for example, istrue
and the phone number is properly validated. However, when the same behavior is recreated in a test using React Testing Library, the validation fails and the phone number is considered invalid even though it should be valid.Steps to Reproduce
GitHub repo: https://github.com/jamenamcinteer/react-intl-tel-input-rtl-validation
Repl.it demo: https://repl.it/repls/WellmadeCompetitivePyramid
yarn start
Phone number is valid
appears.yarn test
Phone number is valid
never shows up. SeeApp.test.js
for the test code andApp.js
for the app code.Environment
The text was updated successfully, but these errors were encountered: