react-stripe-js icon indicating copy to clipboard operation
react-stripe-js copied to clipboard

Guidance on how to test CardElement interaction

Open nicholeuf opened this issue 2 years ago • 0 comments

What happened?

We are trying to do the same thing as https://github.com/stripe/react-stripe-js/issues/214:

I am trying to add tests where a user enters credit card numbers. Do you have any examples of this? We are using Jest + React Testing Library.

In the example below, the onChangeFromStripe function is modifying internal state to flag when the user has completed interaction with the CardElement. We are mocking stripe using the https://github.com/stripe/react-stripe-js/blob/master/test/mocks.js as inspiration. However, we are having trouble mocking the CardElement interaction.

<Label htmlFor={cardHtmlId}>
            Card Details
            <CardElement
                id={cardHtmlId}
                options={{ ...baseStripeStyles, hidePostalCode: true }}
                onChange={onChangeFromStripe}
              />
</Label>

Can you provide any examples on how best to test this scenario or provide helpers for mocking stripe element components?

Environment

No response

Reproduction

No response

nicholeuf avatar Oct 15 '22 18:10 nicholeuf