Testing Async UI
Async components need tests that wait for the UI to reach a meaningful state. Avoid arbitrary sleep calls because they create slow and flaky tests.
Assert loading, success, empty, and error states. If a request is delayed, the test should observe the transition rather than depending on a specific number of milliseconds.
Mock at the network boundary when practical so the component exercises its real data-handling logic.
Key Takeaways
- Wait for observable UI conditions.
- Avoid arbitrary timeouts.
- Test both successful and failed asynchronous paths.