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

233
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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