#flyingace68
1 messages · Page 1 of 1 (latest)
Hi, can you add more details here? What are you seeing? What does your code look like?
Well, there's more to it than this, but here's the block where I'm getting stumped:
const mockStripe = () => ({
elements: jest.fn(() => mockElements()),
createToken: jest.fn(),
createSource: jest.fn(),
createPaymentMethod: jest.fn(),
confirmCardPayment: jest.fn(),
confirmCardSetup: jest.fn(),
paymentRequest: jest.fn(),
registerAppInfo: jest.fn(),
_registerWrapper: jest.fn(),
});
jest.mock('@stripe/react-stripe-js', () => {
const originalStripe = jest.requireActual('@stripe/react-stripe-js');
return {
__esModule: true,
...originalStripe,
Elements: () => {
return mockElements;
},
useStripe: () => {
return mockStripe;
},
useElements: () => {
return mockElements;
},
};
});
useStripe()?.createToken.mockImplementation({
error: {
message: 'Something went wrong',
},
});
I'm told that createToken doesn't have mockImplementation . It's still seeing createToken as the original stripe function and not as a mocked function.
Why are you looking for mockImplementation? Is the intent to test this?
Yes, I want to test what happens if I receive an error instead of a token.
Later I will want to test what happens once I receive a token.
Can you not explicitly pass anything other than a token here to test this?
I will look into that, thanks!