DEV Community

Discussion on: How I structure my React projects

Collapse
 
danielpklimuntowski profile image
Daniel Klimuntowski

Looks well structured.

Personally, I wouldn't put all tests in a separate folder, as I'd have to recreate to whole src structure inside of it, unless I'd stick with a tons of test files. I'd leave test modules next to prod modules, e.g.:

- components
-- MyComponent.tsx
-- MyComponent.test.tsx
- utils
-- strings.ts
-- strings.test.ts

To me the above example looks cleaner than:

- components
-- MyComponent.tsx
- utils
-- strings.ts
- tests
-- MyComponent.test.tsx
-- strings.test.ts

OR:

- components
-- MyComponent.tsx
- utils
-- strings.ts
- tests
-- components
--- MyComponent.test.tsx
-- utils
--- strings.test.ts
Collapse
 
larswaechter profile image
Lars Wächter

In the article I mention that I put components and their accordings tests into the same directory.

The "global" test directory includes tests that do not belong to certain components :)