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

257
Views
Cómo obtener el índice de prueba actual en broma

¿Cómo obtengo el índice de la prueba actual en test.each en jest ?

Así es como estoy haciendo en este momento

 test.each([ [ "Adam", 0 ], // specifying index manually [ "Ron", 1 ], [ "Roy", 2 ], ])( "Student: %s", ( name, currentTestIndex, done ) => { if ( currentTestIndex == 0 ) expect( name ).toEqual( "Adam" ) if ( currentTestIndex == 2 ) expect( name ).toEqual( "Roy" ); return done() } )

Cómo hacerlo sin especificar el índice manualmente

 test.each([ [ "Adam"], // not specifying the index [ "Ron" ], [ "Roy" ], ])( "Student: %s", ( name, currentTestIndex, done ) => { // how to get current test's index ? if ( currentTestIndex == 0 ) expect( name ).toEqual( "Adam" ) if ( currentTestIndex == 2 ) expect( name ).toEqual( "Roy" ); return done() } )

Editar:

Haciéndolo de esta manera ahora, creando otra matriz con map y agregando índice como primer elemento

 test.each([ [ "Adam" ], [ "Ron" ], [ "Roy" ], ].map( (eachArr,ind) => { //creating new array and adding index as the 1st element eachArr.unshift( ind ); return eachArr; }))( "Student: %s", ( currentTestIndex, name, done ) => { if ( currentTestIndex == 0 ) expect( name ).toEqual( "Adam" ) if ( currentTestIndex == 2 ) expect( name ).toEqual( "Roy" ); return done() });

¿Alguna otra forma de obtener el índice, desde la jest sin crear una nueva matriz como la anterior?

about 4 years ago · Juan Pablo Isaza
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!