This repo contains example of testing with react-testing-library. This repo also contains info on how to use jest after RTL and jest are closely related.
- getBy and getAllBy
- queryBy and queryAllBy
- findBy and findAllBy
Testing playground website is useful for generating selectors. Paste your app html code from the browser to the top-left section of the tool. On the top-right you can find your ready to use selectors.
When testing we need to deal with providers like theme, redux, intl etc... Check here for info how to setup all the app custom providers.
Make sure to install Jest VS code extension by Orta. It will add another icon option on the left where you can see all the tests folders/files as a tree. You can see the status of all tests and run them individually.
The best practice is to use userEvent instead of fireEvent, because userEvent is similar to how the user interacts with the browser. More info in the docs.