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.

Don't wrap arrays in `test.each` template strings

See original GitHub issue

Prettier 1.19.1 Playground link

Input:

    test.each`
      givenInteger | givenObjectArray         | givenSimpleArray
      ${1}      | ${[{ start: 5, end: 15 }]} | ${[1,2,3,4,5,6,7,8]}
      ${1}| ${[{ start: 5, end: 15 }]} | ${["test", "string", "for", "prettier"]}
      ${3}      | ${[{ start: 5, end: 15 }]} | ${6}
      ${4} | ${[{ start: 1, end: 3 },{ start: 15, end: 20 },]} | ${15.01}
    `("example test", ({givenInteger, givenObjectArray, givenSimpleArray}) => {})

Output:

test.each`
  givenInteger | givenObjectArray           | givenSimpleArray
  ${1}         | ${[{ start: 5, end: 15 }]} | ${[1, 2, 3, 4, 5, 6, 7, 8]}
  ${1}         | ${[{ start: 5, end: 15 }]} | ${["test", "string", "for", "prettier"]}
  ${3}         | ${[{ start: 5, end: 15 }]} | ${6}
  ${4} | ${[
  { start: 1, end: 3 },
  { start: 15, end: 20 }
]} | ${15.01}
`("example test", ({ givenInteger, givenObjectArray, givenSimpleArray }) => {});

Expected behavior:

I would expect that the givenObjectArray containing multiple objects does not get wrapped and stays in one line and that the alignment is working as expected. This example has been taken from an jest test.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
thorn0commented, May 13, 2020

@yogmel Hi and welcome. Of course you may, go ahead. Let me know if you have questions.

1reaction
yogmelcommented, May 13, 2020

Hi everyone, I’m looking for good-first-bugs to get started contributing to Prettier. May I solve this one if available?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug]: test.each jest template string variables do not work ...
[Bug]: test.each jest template string variables do not work when passing an array of object #12562.
Read more >
How can i wrap loop items in an <li> tag using Template Literals
I am using template literals for this. But when i use the <li> tag inside template literals, it is not works. Can you...
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 >
String Interpolation in JavaScript - Dmitri Pavlutin
The string interpolation in JavaScript is performed by template literals (strings wrapped in backticks ` ) and ${expression} as a ...
Read more >
Using Matchers - Jest
Jest uses "matchers" to let you test values in different ways. ... toEqual recursively checks every field of an object or array.
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