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

why is onChange parameter a string instead of event? #450

Open
daniellizik opened this issue Feb 18, 2025 · 1 comment
Open

why is onChange parameter a string instead of event? #450

daniellizik opened this issue Feb 18, 2025 · 1 comment

Comments

@daniellizik
Copy link

i'm trying to test pasting a E.164 formatted phone number into the input with cypress, but forcefully dispatching an event in a test doesn't work because my application code expects onChange to work with a string, not an event

my code generally looks like

const handleOnChange = (val: sstring) => {
  // stuff here
}

<ReactPhoneInput
  {...inputProps}
  defaultCountry={selectedCountry?.shortName as CountryCode}
  international
  countryCallingCodeEditable={false}
  type="tel"
  data-testid={inputProps['data-testid'] || PHONE_INPUT.INPUT}
  onChange={handleOnChange}
  onPaste={handleOnChange}
/>

and the test

describe('pasting a value', () => {
  it('should update the phone number and trigger onChange when pasting a value', () => {
    mount(<PhoneInput />);

    const E164_COMPLIANT_JP_PHONE_NUMBER = '+817012341234'

    cy.get('input[type="tel"]').paste(E164_COMPLIANT_JP_PHONE_NUMBER);
  });
});
@catamphetamine
Copy link
Owner

catamphetamine commented Feb 19, 2025 via email

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

No branches or pull requests

2 participants