#flyingace68
1 messages · Page 1 of 1 (latest)
Hello, what about the mocking can we help you with?
Well, I was looking at the UI testing docs and I didn't see anything there about how to create a jest.mock for that function so I can see if it has been called.
I want to be able to assert that when form data is entered correctly and the form is submitted that it is sent to Stripe.
Hello?
Sorry server was busy and I was still catching up. Was just getting back to this thread
no worries
We actually recommend against automated filling out and submitting Stripe forms for testing. For those the type of mocking that we typically recommend is to get an example response from Stripe and have your code return that when it is time to mock submit details to Stripe.
I don't want to actually submit data, I just want to be able to verify that if the form is filled out correctly and the user clicks "submit" that stripe.createToken is called.
Gotcha, I will consult my colleagues on this to see if there is another way to test what that test is getting at
For this you would want to not use stripe.js at all. You would want to define your own stripe.createToken method for your code to call during these mock tests and have jest track if that is called
My colleague actually found an example of mocking out these requests with jest! https://github.com/stripe/react-stripe-js/issues/59#issuecomment-632271980