Testing Library/react May 2026
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):
expect(screen.getByText(/loading/i)).toBeInTheDocument(); testing library/react
Greeting.test.jsx
import render, screen, waitFor from '@testing-library/react'; import UserProfile from './UserProfile'; test('loads user data', async () => render(<UserProfile userId=1 />); screen from '@testing-library/react'
npm install --save-dev @testing-library/react @testing-library/jest-dom @testing-library/user-event In your test setup file: import Greeting from './Greeting'