Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

80
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda