Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

84
Visualizações
Does jest-each provide a way to get more access to the passed arguments in the test description?

Given this sample test using TypeScript and Jest based on https://jestjs.io/docs/api#testeachtablename-fn-timeout

  it.each([
    { numbers: [1, 2, 3] },
    { numbers: [4, 5, 6] }
  ])('Test case %#: Amount is $numbers.length => $numbers', ({ numbers }) => {
    expect(true).toBeTruthy();
  });

The test runner only prints

✓ Test case 0: Amount is $numbers.length => $numbers (4ms)

Is there a way I can replace $numbers with its value and work with it? E.g. calling array functions on it.


A working alternative would be

  [
    [1, 2, 3],
    [4, 5, 6]
  ].forEach((numbers, index) => {
      it(`Test case ${index}: Amount is ${numbers.length} => ${numbers}`, () => {
        expect(true).toBeTruthy();
      })
  });

but I don't know if this is the suggested way.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can accomplish this with the template literal implementation of test.each, e.g.:

test.each`
    input | expectation
    ${1}  | ${'expected-1'}
    ${2}  | ${'expected-2'}
    ${3}  | ${'expected-3'}
`('When the input=$input should return $expectation', ({ input, expectation }) => { ...

Note a couple of things about this:

  1. As it's a template literal, you need to enter the values in the table wrapped in ${ }.
  2. You need to format the table carefully with | to delimit the columns
  3. The arguments need to be destructured in the test callback ( { input, expectation} instead of input, expectation)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda