You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now to generate dynamic test names based on test input when using it.each jest has invented its own string replacement syntax which is non idiomatic to javascript and clunky to use. It lacks type safety and requires new devs to learn the syntax which is not ideal. Instead, it.each could just take a function that returns a string and receives the same input parameters as the test function itself:
consttestCases=[{name: "my name"}];// oldit.each(testCases)("testing $name",(obj)=>{})// newit.each(testCases)((obj)=>`testing ${obj.name}`,(obj)=>{})
AFAIK the above old version does not support passing arrays in any way so doing something like [[{name: "my name"}]] isn't possible either, which can be really annoying some times in cases where you want to pass one object containing all of your test data rather than a bunch of parameters and have many test cases:
consttestCases=[[{name: "name1"}],[{name: "name2"}]];// How do I get name from this??
And even if it does support it and I missed that in the docs, imagine how much easier it would have been for me and others if it was just a function returning a string in nice idiomatic javascript? I've seen the template string solution which I think possibly supports the above but at that point the api for this is just getting wacky in my opinion. Just use a function and there are 50 less things to learn and it supports all use cases.
Motivation
Above suggested API is clearly more intuitive and easier to learn IMO, and has much greater flexibility as JS code can run in the function in cases where more advanced formatting is useful. AFAIK the above does not support passing arrays in any way so doing something like [[{name: "my name"}]] isn't possible either, which can be really annoying some times in cases where you want to pass one object containing all of your test data rather than a bunch of parameters and have many test cases.
Example
No response
Pitch
It will reduce the learning curve while improving type safety and flexibility of the API. It just makes the library easier to use and to learn in a non-trivial way. Initial implementation can allow using the old syntax or optionally passing a function returning a string with the new syntax so it's backwards compatible
The text was updated successfully, but these errors were encountered:
🚀 Feature Proposal
Right now to generate dynamic test names based on test input when using
it.each
jest has invented its own string replacement syntax which is non idiomatic to javascript and clunky to use. It lacks type safety and requires new devs to learn the syntax which is not ideal. Instead, it.each could just take a function that returns a string and receives the same input parameters as the test function itself:AFAIK the above old version does not support passing arrays in any way so doing something like
[[{name: "my name"}]]
isn't possible either, which can be really annoying some times in cases where you want to pass one object containing all of your test data rather than a bunch of parameters and have many test cases:And even if it does support it and I missed that in the docs, imagine how much easier it would have been for me and others if it was just a function returning a string in nice idiomatic javascript? I've seen the template string solution which I think possibly supports the above but at that point the api for this is just getting wacky in my opinion. Just use a function and there are 50 less things to learn and it supports all use cases.
Motivation
Above suggested API is clearly more intuitive and easier to learn IMO, and has much greater flexibility as JS code can run in the function in cases where more advanced formatting is useful. AFAIK the above does not support passing arrays in any way so doing something like
[[{name: "my name"}]]
isn't possible either, which can be really annoying some times in cases where you want to pass one object containing all of your test data rather than a bunch of parameters and have many test cases.Example
No response
Pitch
It will reduce the learning curve while improving type safety and flexibility of the API. It just makes the library easier to use and to learn in a non-trivial way. Initial implementation can allow using the old syntax or optionally passing a function returning a string with the new syntax so it's backwards compatible
The text was updated successfully, but these errors were encountered: