0

I saw the following code from another question:

....(more code above)

describe(findPairwise.name, () => {
  it.each`
    array        | predicate                                | expected
    ${[1, 2, 3]} | ${(l: number, r: number) => l === 1}     | ${[1, 2]}
    ${[1, 2, 3]} | ${(l: number, r: number) => r === 2}     | ${[1, 2]}
    ${[1, 2, 3]} | ${(l: number, r: number) => r === 3}     | ${[2, 3]}
    ${[1, 2, 3]} | ${(l: number, r: number) => l + r === 5} | ${[2, 3]}
    ${[1, 2, 3]} | ${(l: number, r: number) => l === r }    | ${[undefined, undefined]}
  `
  ('should return $expected for $array and $predicate', ({ array, predicate, expected }) => {

....(more code below)

I do not understand why he can do it.each follow by a template string, may I know what language feature is this?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
Kallzvx
  • 594
  • 7
  • 23
  • 2
    Did you read [the docs](https://jestjs.io/docs/api#testeachtablename-fn-timeout)? As they say it's a _tagged template_ literal, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates. – jonrsharpe Feb 06 '23 at 20:31
  • @jonrsharpe hi, yes, it says `it.each`table`(name, fn)` is an alias, but I do not understand why it can be written this way – Kallzvx Feb 06 '23 at 20:32
  • @jonrsharpe Ah right, now I understand it, thanks! – Kallzvx Feb 06 '23 at 20:32
  • (And frankly I wouldn't bother using it - https://stackoverflow.com/a/72117404/3001761.) – jonrsharpe Feb 06 '23 at 20:33
  • I see, make sense, thanks for the informative link! – Kallzvx Feb 06 '23 at 20:34

0 Answers0