9

Can anyone explain to me what is the difference between testRegex and testMatch in Jest configuration? (https://jestjs.io/docs/en/configuration)

I understand that I should not define them both but in what situation shall I use one and not the other?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Ziv Levy
  • 1,904
  • 2
  • 21
  • 32

1 Answers1

9

jest.testMatch accepts an array of glob patterns. Like when you use ls p* to list every file in the current directory which starts with a p.

jest.testRegex accepts a regex string, which is way more powerful (but maybe an overkill for what you're trying to achieve).

I'd use the one you're more familiar with. It would be redundant to set both.

Although, for some complex cases, you are better off with a regex. If you want jest to only test files that start with a p and have exactly three numbers in fixed places and the filename ends with .test or .jest, go for a regex. But don't do that anyway.

eloyesp
  • 3,135
  • 1
  • 32
  • 47
axm__
  • 2,463
  • 1
  • 18
  • 34