Jest: Documentation does not contain file structure/naming conventions

Created on 3 Jun 2017  ยท  1Comment  ยท  Source: facebook/jest

Feeling really dumb here. I can't find any information in the docs to describe how Jest finds tests, or where I should put all my test files, or what filename conventions to use. The Getting Started example uses sum.js and sum.test.js, does that mean I should write all my tests in files right beside the source file with the convention [filename].test.js? It would be nice if this were explicitly stated somewhere.

Searching through Google I also found that there's a __tests__ directory that can be used alternatively. Does Jest parse every JS file in __tests__ directories, or do I need to follow some naming convention? I can't find reference to __tests__ anywhere in the docs.

Can someone create a section in Getting Started to explain the different options here and the recommended approach?

I understand the docs may want to take an unopinionated stance, but for newcomers having some type of default will lower the barrier to adopting new technologies.

Documentation good first issue

Most helpful comment

Here you go :) http://facebook.github.io/jest/docs/configuration.html#testregex-string

And this is a small visualisation of this regex:

โ”œโ”€โ”€ __tests__
โ”‚   โ””โ”€โ”€ component.spec.js # test
โ”‚   โ””โ”€โ”€ anything # test
โ”œโ”€โ”€ package.json # not test
โ”œโ”€โ”€ foo.test.js # test
โ”œโ”€โ”€ bar.spec.jsx # test
โ””โ”€โ”€ component.js # not test

I think it's a great opportunity for a first contribution. Feel free to send a PR we'd love to review and merge it!

>All comments

Here you go :) http://facebook.github.io/jest/docs/configuration.html#testregex-string

And this is a small visualisation of this regex:

โ”œโ”€โ”€ __tests__
โ”‚   โ””โ”€โ”€ component.spec.js # test
โ”‚   โ””โ”€โ”€ anything # test
โ”œโ”€โ”€ package.json # not test
โ”œโ”€โ”€ foo.test.js # test
โ”œโ”€โ”€ bar.spec.jsx # test
โ””โ”€โ”€ component.js # not test

I think it's a great opportunity for a first contribution. Feel free to send a PR we'd love to review and merge it!

Was this page helpful?
0 / 5 - 0 ratings