-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
test.each
should perform string interpolation with object properties
#10394
Comments
@mattphillips thoughts? Seems reasonable to me |
This has been something I've wanted to add for a while but not got around to it and I think we should add parity with the tagged template table with |
Hey @mattphillips, I was looking at the code to see how I could contribute this change. Was wondering what your thoughts were on ensuring it's not breaking. Perhaps if the test name contains any of the printf special characters, use the printf formatting logic, else use variable interpolation? |
Found this in my inbox and noticed it hasn't been replied to, so I'll just go ahead and answer from my perspective 😅 |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
🚀 Feature Proposal
When giving an array of objects to the
test.each
overload that accepts an array, and not a template strings table, jest should interpolate the object's properties into the test name.Motivation
The current interpolation of template strings works great, but it doesn't provide any hook for type-safety. This is problematic when scaling up to large and complex test cases, and in TypeScript, it allows
any
to sneak into your test functions. It also is more intuitive, it left me wondering for a while why a transformation to a type-safe version of a test wasn't causing interpolation of the test case.Example
We can do something like this right now:
Which will output the test cases:
√ add(1, 1) === 2
√ add(2, 2) === 4
In order to achieve type-safety on the same test, I would make this transformation:
Which I would expect should output the same test cases as above, but instead:
√ add($a, $b) === $expectedResult
√ add($a, $b) === $expectedResult
Pitch
It is isomorphic to functionality in the core library, but I believe it cannot be implemented as an extension.
The text was updated successfully, but these errors were encountered: