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

154
Views
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
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!