Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error for incompatible card data type in createToken #19

Merged
merged 2 commits into from
Mar 17, 2020

Conversation

hofman-stripe
Copy link
Contributor

@hofman-stripe hofman-stripe commented Mar 17, 2020

Switch order of the createToken overload to give precedence to CardElement over IbanElement.

Summary & motivation

See stripe/react-stripe-js#47

Testing & documentation

Added tests for expected typescript errors.

Switch order of `createToken` overload.
Add tests for expected typescript errors.
@hofman-stripe hofman-stripe force-pushed the hofman/improve-create-token-type-error branch from 72ac38f to a98b40c Compare March 17, 2020 01:30
Copy link
Contributor

@christopher-stripe christopher-stripe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat!

I have some slight FUD (not blocking) about putting this in out test suite, since we tend to be extremely hesitant in deleting tests or changing assertions. If we upgrade TS and the error messages change to something worse, are we OK updating these tests? If we make some unrelated improvement to the types and the error messages get worse, are we OK updating the tests? It seems like this optimized a local minima in the DX (one out of many possible errors), but are pinning ourselves to that optimization in the test suite.

])('%s', (fileName, expectedError) => {
expect(
getError(path.resolve(__dirname, `./fixtures/${fileName}.ts`))
).toMatch(expectedError);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(2) Could also be a nice fit for snapshots, perhaps with a custom serializer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right above, we should relax the match, not make it more strict. The flattened error has a lot of "stack" which may vary over versions.

@hofman-stripe
Copy link
Contributor Author

Yeah I was considering relaxing the tests:

  • Remove the Iban test
  • Only search for extra_property to be in the card error message.

That way the only thing we'd test is that the error for card token mentions the extra property, which is the best approximation we can get for a meaningful message.

WDYT?

@christopher-stripe
Copy link
Contributor

Nice, relaxing the tests should help a lot.

@hofman-stripe hofman-stripe merged commit ce6e182 into master Mar 17, 2020
@hofman-stripe hofman-stripe deleted the hofman/improve-create-token-type-error branch March 17, 2020 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants