¿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?