Unit tests are written to verify the functionality of "units" (small pieces) of code. Hence, good unit tests do not test implementation details. Instead, they should test the behavior of the code being tested.
This is a list of patterns and anti-patterns widely used when testing react applications.
- Check if a component exists
- Simulating action on a button
- Testing change in props
- Testing if callback is called
- Testing if a dependency was called
Examples could be found in the examples/src
folder. They are grouped by test behavior.
Patterns can be found in the pattern.test.js
file. (I usually name tests after my component so that it is easy to understand)
Anti-patterns can be found in antipattern.test.js
along side the pattern.test.js
.
Send a Pull Request with patterns you have found interesting when testing React
code with jest
and enzyme
. You can also share some antipatterns you have come across. Please explain why you think of it as a pattern/anti-pattern in the commit message.
If you have any feature requests, please create an issue in this repository.
If you have any comments on the patterns/anti-patterns listed here, let's discuss in comments 😊