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

166
Vistas
Jest testing a loop with Booleans

I have the following function in Jest. I have a method called isAquatic that returns a bool depending on the animal.

        const nonAquaticAnimal = ["tiger", "cat", "lion"]
        test.each(nonAquaticAnimal)(
          '.isAquatic',
          (input, false) => {
            const animal = isAquatic(input)
            expect(animal).toBe(false);
          },
        );

I have an error that says identifier false is a reserved word and cannot be used here. How can I loop through the array and call this method which returns a boolean?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The array argument passed to test.each is usually a 2D array, so you can have the animal and the expected result for that animal in the nonAquaticAnimals array. And the test function would both the items in as function arguments.

You can have your test as follows:

const nonAquaticAnimals = [
  ["tiger", false],
  ["cat", false],
  ["lion", false],
];
test.each(nonAquaticAnimals)(".isAquatic", (animal, expected) => {
  expect(isAquatic(animal)).toBe(expected);
});

You can also omit the expected value from your array if you find it redundant:

const nonAquaticAnimals = ["tiger", "cat", "lion"];
test.each(nonAquaticAnimals)(".isAquatic", (animal) => {
  expect(isAquatic(animal)).toBe(false);
});
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