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

321
Vistas
Mocha loop at the middle of describe function

Can we run a dynamical loop test in mocha when we obtain the dynamic array from one of the test cases something like below?

describe('test', () {
  var array = []; 
  it('test 1', function(done) {
    // get the array
    // assume JSON = [ {number : 1, value : 1}, {number : 2, value : 2}]
  }
  // run loop test base on the array from test 1
  array.forEach() {
    it(`test {array.number}`, function(done) {
      // sample
      expect(array.number).to.be.equal(array.value)
    }
  }

  it('test 3', function(done) {
    // another test 
  }
}

So far, it seems to work fine if I ran in a separate js file instead of just one js file by passing the result of the JSON array (callback) to another test js file. What if I want it in one js file?

Reference: https://mochajs.org/#dynamically-generating-tests

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