question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support shallow arrays in jest-each

See original GitHub issue

I 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:

screen shot 2018-05-29 at 2 50 19 pm

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.

@mattphillips

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
captbaritonecommented, May 29, 2018

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.

0reactions
github-actions[bot]commented, May 12, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found