Best practices
While tools provide a solid foundation, the most important aspects of testing transcend them. Writing great tests remains your task.
In this exercise block, we will go through some of the absolutely essential best practices when it comes to writing integration tests. I've written extensively about the true purpose of testing, what makes a great test, and why you want to write tests that fail. All of those still apply. Today, let's add another layer to your testing expertise by focusing on how to write fantastic integration tests.
What we will cover
There are countless practices, patterns, and tips when it comes to testing. Some general, others extremely specific. For this block, I've trimmed all of these down to the following topics:
- Accessibility selectors. Write tests that find HTML elements the same way your users find them.
- User events. Write tests that interact with HTML elements the same way your users do.
- Network mocking. How to mock network requests in your tests with Mock Service Worker.
- Element presence. How to test elements presence, especially when something must not appear in the UI.
- Page navigation. Testing page transitions (i.e. routing) at the integration test level.
Mastering these five areas will give you a strong foundation for writing quality tests. Let's explore them.