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

196
Views
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 answers
Answer question

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