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

156
Vistas
nodejs async await inside iterator for loop in mocha test

I'm trying to test the usage of an asynchronous generator using the async and await paradigm.

I have a generator function yielding results from a stream:

async function* getChunkOfData(filepath) {
  try {
    const inputStream = fs.createReadStream(filepath);
    const parser = parse();
    await pipelineAsync(inputStream, parser);
    for await (const line of parser) {
      yield line;
    }
  } catch (err) {
    throw new Error("error while reading csv file: " + err.message);
  }
}

I'm getting line by line in my test and using it as input for an asynchronous function. From the test, I'm getting a timeout error and only the first iteration of the for loop is executed. Here my test code:

describe("My test suite", function () {
  it("My test", async function () {
    try {
      const iterator = getChunkOfData("example.csv");
      for await (const row of iterator) {
        await asyncCall(row);
        // some expect logic using chai
      }
    } catch (err) {
      console.log(await err);
      assert.throw(err);
    }
  });
});

Please note, that I've already tried to increase the test timeout, without any better results also because the asyncCall is executed quite fastly.

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