references/test_automation_patterns.md · 24000
ine snapshots for small outputs** - Easier to review in code 3. Review snapshot changes carefully - Don't blindly update 4. Avoid snapshots for dynamic content - Filter out timestamps, IDs 5. Combine with other assertions - Snapshots complement, not replace
// Filtering dynamic content from snapshots
it('renders user card', () => {
const { container } = render(<UserCard user={mockUser} />);
// Remove dynamic elements before snapshot
const card = container.firstChild;
const timestamp = card.querySelector('.timestamp');
timestamp?.remove();
expect(card).toMatchSnapshot();
});
Summary
- Use Page Objects for complex, reusable page interactions
- Build factories for consistent test data creation
- Leverage MSW for realistic API mocking
- Create custom render utilities for provider wrapping
- Master async patterns to avoid flaky tests
- Use snapshots wisely for stable, static content only