Chiawen
Chiawen

Reputation: 11789

How to run jest on files not ending in .test.js or .spec.js?

I have files tests/foo.js tests/bar.js. When I run jest tests/foo.js or jest tests/*.js, no test is run. How do I run test on files not ending in .test.js?

Upvotes: 1

Views: 1584

Answers (2)

Brian Adams
Brian Adams

Reputation: 45810

Jest uses testMatch to find tests:

By default it looks for .js, .jsx, .ts and .tsx files inside of __tests__ folders, as well as any files with a suffix of .test or .spec (e.g. Component.test.js or Component.spec.js). It will also find files called test.js or spec.js.

In your case you can set testMatch to the following:

testMatch: [ "**/tests/**/*.[jt]s?(x)" ]

...and it should find the tests you have created in your tests folder.

Upvotes: 2

mgarcia
mgarcia

Reputation: 6325

You can define the patterns jest uses to detect test files through the testRegex or testMatch options.

Upvotes: 1

Related Questions