Skip to content

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

@daniellizik

Description

@daniellizik

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);
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions