Support shallow arrays in jest-each
See original GitHub issueI expected I could write this:
test.each(['red', 'green', 'bean'])("The word %s contains the letter 'e'", word => {
expect(/e/.test(word)).toBe(true);
});
But it lead to very confusing test titles and test failures:
I ended up doing something like this, and it worked.
test.each(['red', 'green', 'bean'].map(word => [word]))(
"The word %s contains the letter 'e'",
word => {
expect(/e/.test(word)).toBe(true);
},
);
At the very least, it would be nice to error if the values in the table are not arrays.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Using Matchers - Jest
Jest uses "matchers" to let you test values in different ways. This document will introduce some commonly used matchers. For the full list, ......
Read more >Reduce boilerplate test code with Jest it.each | by E.Y. - Medium
table : Array of Arrays with the arguments that are passed into the test fn for each row. name : String the title...
Read more >jest-each | Yarn - Package Manager
jest-each allows you to provide multiple arguments to your test / describe which results in the test/suite being run once per row of...
Read more >shallow copying an array of an array - Stack Overflow
You might do it like this: const fillWith = () => Array.from({length: 5}, (_, i) => i + 1); const arr = Array.from({length:...
Read more >React-native-template-nascam-template NPM - npm.io
... array-filterarray-includesarray-maparray-reducearray-slicearray-uniqueart ... -visitcolor-convertcolor-namecolor-supportcolorettecombined-streamcommand- ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think option two is best, since I would imagine it’s pretty common to want to make the same assertion about an array of values, and having to manually convert the array to a table is kinda gross.
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. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.