Ad

Jest Test Formatting -- __tests__ Vs *.test.js

- 1 answer

I'm working in a react codebase where we have test files labeled

__tests__

The files inside look like this

filename.js

Previously when I've used jest/enzyme, I've had test files formatted like this

filename.test.js

I am assuming that when you put a file inside a folder with the title

__tests__ 

you can leave the .test part off? I can't seem to find a solid answer on topic. Does anyone have some insight into the formatting functionality?

Ad

Answer

This is because of the value of jest config's testMatch property which defaults to

[ "**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)" ]

Which basically means that it will consider as a test any js(x) or ts(x) file either with .test (or .spec) after it or inside a __test__ folder.

Ad
source: stackoverflow.com
Ad