React Testing Library -
// Navigate to profile await userEvent.click(screen.getByRole('link', { name: /profile/i })) expect(screen.getByText(/user profile/i)).toBeInTheDocument()
expect(handleSubmit).toHaveBeenCalledWith({ email: 'test@example.com', password: 'password123' }) }) import { renderHook, act } from '@testing-library/react' test('useCounter hook increments', () => { const { result } = renderHook(() => useCounter(0)) react testing library
// Submit await userEvent.click(screen.getByRole('button', { name: /submit/i })) // Navigate to profile await userEvent
// Logout await userEvent.click(screen.getByRole('button', { name: /logout/i })) expect(screen.getByRole('button', { name: /login/i })).toBeInTheDocument() }) { name: /logout/i })) expect(screen.getByRole('button'
React Testing Library encourages writing accessible, user-focused tests that give you real confidence in your application. The key is always asking: "Is this how a user would interact with and observe this component?"
// Wait for loading to complete expect(screen.getByText(/loading/i)).toBeInTheDocument()
// Find elements const button = screen.getByRole('button', { name: /increment/i }) const count = screen.getByText(/count: 0/i)