Naming Tests
Explore how to write well-named tests in Jest that clearly state what is tested, the input or state, and expected behavior. Learn to group tests with describe blocks or separate test files to improve test organization and readability. Understand using Jest's verbose mode to view detailed test outputs and adopt best practices for writing maintainable and clear tests in React applications.
Using a consistent and meaningful naming strategy
A well-named test will help us quickly identify which test is failing and the area of the actual code that the problem might be in.
A well-named test will contain the following:
- What is being tested.
- The input to the thing being tested or the state of the thing being tested.
- The expected output or expected behavior.
It is helpful to have a naming convention for tests. This guarantees that the above aspects of a test are covered in the name. If the naming is consistent, we will very quickly understand the aspects of any test.
An example naming ...