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

232
Views
Running jest tests in parallel based on a list of parameters

In my case I have a test file containing a few hundred tests using jest

describe('my test-suite', () => {
   test('test 1', () => {
       expect(1).toBe(1);
   });
   //another hundred tests...
});

What I need to do now is to run these tests for different parameters, specified on a config file. More in details in my case the config file specifies some external parameters for external services (think like DB access parameters) and ideally I would like to keep exactly the same structure I already have, running the same tests multiple times against all these external services.

Ideally I should be able to do something like:

const paramList = [{
    name: 'service 1'
}, {
    name: 'service 2'
}];

describe('my parallel test-suite', () => {
    it.each(paramList)("testing against $name", ({name}) => {

        //just what I had before
        describe('my test-suite', () => {
           test('test 1', () => {
               expect(1).toBe(1);
           });
           //another hundred tests...
        });

    });
});

Ideally the next step would be to replace the test.each with test.concurrent.each and being able to run my tests in parallel against all the different external services.

Unfortunately with the code (and Jest version 27.4.7) above what I get is:

Cannot nest a describe inside a test. Describe block "my test-suite" cannot run because it is nested within "service service 1".

Tests cannot be nested. Test "test 1" cannot run because it is nested within "service service 1".

Is there a way to achieve what I'm trying to do here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can't run a describe block in an each loop. Run each test in its own loop and then it will work. Something like this:

describe('my parallel test-suite', () => {
    it.each(paramList)("testing against $name", ({name}) => {
        expect(1).toBe(1);
    });
    it.each(paramList)("another test against $name", ({name}) => {
        expect(2).toBe(2);
    });
    //another hundred tests...
});
about 4 years ago · Juan Pablo Isaza Report
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!