Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest's testRegex and testMatch

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?

like image 690
Ziv Levy Avatar asked Oct 19 '18 13:10

Ziv Levy


1 Answers

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.

like image 102
axm__ Avatar answered Nov 15 '22 16:11

axm__