Testing Library/react ✦ Instant Download

import render, screen, waitFor from '@testing-library/react'; import UserProfile from './UserProfile'; test('loads user data', async () => render(<UserProfile userId=1 />);

npm install --save-dev @testing-library/react @testing-library/jest-dom @testing-library/user-event In your test setup file: testing library/react

import render, screen from '@testing-library/react'; import Greeting from './Greeting'; test('displays the correct greeting', () => render(<Greeting name="Alice" />); const heading = screen.getByText(/hello, alice!/i); expect(heading).toBeInTheDocument(); ); Use userEvent (recommended over fireEvent for realistic behavior): waitFor from '@testing-library/react'

import render, screen from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import ToggleButton from './ToggleButton'; test('toggles text on click', async () => const user = userEvent.setup(); render(<ToggleButton />); import UserProfile from './UserProfile'

expect(button).toHaveTextContent(/on/i); ); For API calls or async updates: