Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

315
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda