-
Notifications
You must be signed in to change notification settings - Fork 196
Open
Description
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
- https://gist.github.com/nickytonline/bcdef8ef00211b0faf7c7c0e7777aaf6
- https://stackoverflow.com/questions/60111777/paste-test-in-cypress-in-reactjs-project
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
Labels
No labels