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

194
Visualizações
How to grep a test in Mocha with a specific name and under a specific parent?

Consider the following test cases:

describe("parent1", () => {
    it("mytest", () => {
        // ...
    });
});

describe("parent2", () => {
    it("mytest", () => {
        // ...
    });
});

describe("parent1", () => {
    it("myothertest", () => {
        // ...
    });
});

describe("parent2", () => {
    it("myothertest", () => {
        // ...
    });
});

I basically want to be able to run, via commandline, mytest under parent1.

Attempts

If I try the following:

mocha --grep 'mytest'

It will end up running:

  • parent1/mytest
  • parent2/mytest

Whereas if I try:

mocha --grep 'parent1'

It will end up running:

  • parent1/mytest
  • parent1/myothertest

How to achieve this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It was actually quite simple since this is evaluated as a regex:

mocha --grep 'parent1 mytest'

Using a space is the solution it seems. I can successfully pinpoint tests like that.

Notes

It also works if test names have spaces in them:

describe("parent1", () => {
    it("my test", () => {
        console.log("AAA");
    });
});

describe("parent2", () => {
    it("my test", () => {
        console.log("BBB");
    });
});

describe("parent1", () => {
    it("my other test", () => {
        console.log("CCC");
    });
});

describe("parent2", () => {
    it("my other test", () => {
        console.log("DDD");
    });
});

Running:

mocha --grep 'parent1 my test'

Would work as expected.

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