Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest with special tests run on occasion

How do I write Jest tests that only runs when specifically invoked on the command line?

I want to have integration-like tests that interact with online services from Google and Amazon in a React project.


If I create a differently named test file src/google.itest.js:

  • Good: It is not normally run by jest
  • Good: It resides where all other tests are
  • Bad: jest cannot be made to run it:

jest --testPathPattern="\.itest"
Jest still does not run the tests, probably because it is blocked by the testMatch configuration option: testMatch:

**/__tests__/**/*.js?(x),**/?(*.)(spec|test).js?(x)

How do I write Jest tests that only runs when specifically invoked on the command line?

like image 471
Keith Avatar asked Jan 28 '26 17:01

Keith


1 Answers

It works with RegExp (presumably those are ECMAScript regexps):

jest --testRegex 'src/.*itest.*'

Note that an equal sign separating the long option and its value is not required

like image 141
Keith Avatar answered Jan 31 '26 06:01

Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!