Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jest test formatting -- __tests__ vs *.test.js

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?

like image 939
J Seabolt Avatar asked Apr 06 '19 16:04

J Seabolt


People also ask

What is transformIgnorePatterns?

transformIgnorePatterns [array<string>] Default: ["/node_modules/"] An array of regexp pattern strings that are matched against all source file paths before transformation. If the test path matches any of the patterns, it will not be transformed.

Does Jest run tests in order?

Order of Execution​ Once the describe blocks are complete, by default Jest runs all the tests serially in the order they were encountered in the collection phase, waiting for each to finish and be tidied up before moving on.

Do Jest tests run in parallel?

Each time a test run completes, the global environment is automatically reset for the next. Since tests are standalone and their execution order doesn't matter, Jest runs tests in parallel.

How do you match objects in Jest?

To match part of an Array in Jest, we can use expect. objectContaining(partialObject) .


1 Answers

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.

like image 105
ManavM Avatar answered Oct 10 '22 09:10

ManavM