Jest: Why use jest dubble underscore in __tests__ folder name?

Created on 8 Dec 2015  路  5Comments  路  Source: facebook/jest

I saw this conversion in Python but it has other meaning.

Python PEP 8:
double_leading_and_trailing_underscore: "magic" objects or attributes that live in user-controlled namespaces. E.g. init, import or file. Never invent such names; only use them as documented.

Why not __tests, _tests_ _tests or tests ?

Most helpful comment

It appears you actually need to use the following config now . . .

"jest": {
  "testMatch": ["**/tests/**/*.js"]
}

All 5 comments

You can adjust the name of your tests-directory with the testDirectoryName configuration option.

Why __tests__? I guess it was just picked randomly to reduce the likelihood of collisions with other directories that might be named tests for any reason and to signal that it only contains (jest-)tests and no actual production code.
An additional advantage of having a non-alphanumeric character as the first char is, that it wont be between "production"-code directories when doing a ls.

@clentfort thanks :+1:

It appears you actually need to use the following config now . . .

"jest": {
  "testMatch": ["**/tests/**/*.js"]
}

At first place, Jest looks for a directory named __tests__ to check for your tests.

We can improve it this way:

"jest": {
  "testMatch": ["**/tests/**/*spec.js"]
}

Because Jest looks for spec.js files instead. Plus if we test Vue.js application, we usually put setup.js file in the tests folder, so without this improvement, Jest will complain about the absence of a test suite in setup.js file.
```

Was this page helpful?
0 / 5 - 0 ratings