Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
Broma probando un bucle con booleanos

Tengo la siguiente función en Jest. Tengo un método llamado isAquatic que devuelve un bool dependiendo del animal.

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

Tengo un error que dice que el identifier false is a reserved word and cannot be used here . ¿Cómo puedo recorrer la matriz y llamar a este método que devuelve un valor booleano?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

El argumento de matriz pasado a test.each suele ser una matriz 2D, por lo que puede tener el animal y el resultado esperado para ese animal en la matriz nonAquaticAnimals . Y la función de prueba incluiría tanto los elementos como argumentos de función.

Puede realizar su prueba de la siguiente manera:

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

También puede omitir el valor expected de su matriz si lo encuentra redundante:

 const nonAquaticAnimals = ["tiger", "cat", "lion"]; test.each(nonAquaticAnimals)(".isAquatic", (animal) => { expect(isAquatic(animal)).toBe(false); });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!