The 'Does the User Care?' Litmus Test
You'll learn a simple question to ask yourself when deciding what to test: would a user notice this?
The Core Principle
When writing tests, you should constantly ask: "Does the user care about this?" If users can't see it, click it, read it, or interact with it in any way, it's likely an implementation detail you shouldn't test.
This litmus test is your decision-making compass. Users don't care about:
- State variable names (
isOpenvsisVisible) - Whether you used
useStateoruseReducer - Component method names or internal function calls
- The order of hooks
- CSS class names (unless they affect visibility)
Users do care about:
- What text appears on screen
- Whether buttons work when clicked
- If forms submit correctly
- Loading and error states they see
- Accessibility features like keyboard navigation
An Analogy
Think of a restaurant customer. They care about the food's taste, temperature, and presentation. They don't care if the chef used a gas or electric stove, which pans were used, or the order ingredients were added—those are implementation details that don't affect their experience.
Applying the Test
Before writing an assertion, pause and ask: "Would a real user notice if this changed?" If you refactor from a class component to a hook, or rename a state variable, should your tests break? No—because the user experience didn't change.
Key Takeaway: If users can't perceive it, don't test it. Focus your assertions on the visible, interactive behavior that affects the user experience.