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

211
Views
Improving Jest testMatch pattern matcher

I am using Jest and using this 'testMatch' pattern to match my test files inside jest.config.js:

testMatch: ['**/?(*.)+(spec).[j|t]s?(x)']

But it is incorrectly picking up some files that end in spec.js. I would like it to only match .spec.js but anything I try results in no files being found.

This regular expression seems to do what I want /.*\.spec\.[j|t]sx?/ but I think these pattern matchers work slightly differently

What do I have to change to make it only pick up [something].spec.js files (or jsx/ts/tsx)?

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

0

As you noted, these patterns aren't actually regex. If you're looking for a keyword to start your search, they're a form of "glob patterns." Also I might be mistaken but I'm pretty sure you want either [jt] or (j|t), not [j|t], may not matter though.

That being said, it sounds like you prefer regex syntax to glob syntax. I can't say I blame you! Instead of trying to figure out the glob that produces the same behavior as the regex you're after, you may want to look at the --testRegex option instead (which is also the property name for your jest.config.js file).

take a look here: https://jestjs.io/docs/configuration#testregex-string--arraystring As a bonus, for reasons that make no sense, testMatch can only take an array of patterns, but testRegex can take either a string (if you have just one pattern to match) or an array

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!