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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With