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

I expect valid value to return valid = true from initial onPhoneNumberChange #343

Open
BramKaashoek opened this issue May 12, 2020 · 4 comments
Assignees

Comments

@BramKaashoek
Copy link

BramKaashoek commented May 12, 2020

 test('the base component', () => {
    let isValid = undefined;
    render(
      <IntlTelInput
        value={'+447400123456'}
        defaultCountry={'GB'}
        onPhoneNumberChange={(valid: boolean, number: string, country: any) => {
          isValid = valid;
        }}
      />
    );

    expect(isValid).toBe(true);
  });

This spec in my own project fails while it should pass. When I implement an equivalent spec in a fork of your react-int-tel-input project, it passes:

 it('validates initial value', () => {
      let valid
      this.params = {
        ...this.params,
        value: '+447400123456',
        defaultCountry: 'GB',
        onPhoneNumberChange: (isValid, number, country) => {
          valid = isValid
        },
      }
      const subject = this.makeSubject()
      expect(valid).toBe(true)
    })
@mcataford
Copy link
Collaborator

Hi @BramKaashoek!

Thanks for reporting the issue! You mention a fork, are there any changes in that fork that aren't in master? I'm going to dig into this and see what I can find.

@mcataford mcataford self-assigned this Jun 16, 2020
@mcataford
Copy link
Collaborator

It appears that this issue is related to #347 (and subsequently is being worked on in #348) and boils down to RTL not playing nice with the dynamic import that supports phone validation. Work is underway to remedy that, in the meantime, having an import for libphonenumber-js-utils in your test file should remove the asynchronousness of the import and allow your test to behave as if the validation was already ready. You can use this technique as a temporary workaround while the dynamic import is either being removed or handled better.

@DamageSami
Copy link

I am facing this same issue, phone number validation never passes. The issue came up when migrating my existing project from CRA to Vite. The workaround causes another error message: Uncaught TypeError: Cannot use 'in' operator to search for 'intlTelInputUtils' in undefined.

I can do a minimal reproduction of the problem (if someone is maintaining this project). With my previous CRA-installation, the input worked fine.

@ychakroun
Copy link

I am facing the same issue as you @DamageSami when i migrate my project to VITE, so i install https://github.com/catamphetamine/libphonenumber-js#validate-phone-number to validate it by my own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants