Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why are Jest test naming conventions the way they are? [closed]

Why are Jest test naming conventions the way they are?

  • Why are test folders named __tests__, with the underscores?
  • Why are test files suffixed with -test.js as opposed to just something.js?
like image 487
Lewis Chung Avatar asked Jan 07 '16 22:01

Lewis Chung


People also ask

Which is the proper naming convention of a test case?

Test class naming convention usually follows the naming convention of the class being tested, e.g., the class under test is “Order” the corresponding test class will be “OrderTests“. When in doubt, it is a good practice to model the test class name after the production class it is testing.

How should I name my tests?

Test name should be presented as a statement or fact of life that expresses workflows and outputs. Test name could include the name of the tested method or class.

What is Je BeforeEach?

BeforeEach in Jest is part of the setup and teardown process. As the name suggests, if we want to run a function or some other code repeatedly “before each” test that code can be put in the beforeEach function.


1 Answers

Underscores and double underscores are commonly used to denote things which are outside of the regular code. For example, Python uses them to prefix object properties which are private or system-controlled.

In this sense, your tests folder isn't part of your app, it's something which sits alongside it. To stretch a hypothetical example, imagine you were writing an app to control science experiments. You might want a folder called, legitimately, tests. That would be arguably insane, the point is that __tests__ makes it clear that the tests are not part of the main line of code.

The -test suffix is just for test discovery. Lots of frameworks use similar prefix or suffix conventions.

like image 147
N3dst4 Avatar answered Sep 21 '22 12:09

N3dst4